-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from thettunaung-carro/test/add-test-cases
feat: add test cases
- Loading branch information
Showing
12 changed files
with
503 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Run tests | ||
on: | ||
push: | ||
paths: | ||
- "**.php" | ||
- "phpunit.xml" | ||
- "composer.json" | ||
- "composer.lock" | ||
|
||
jobs: | ||
pest: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.2 | ||
tools: composer:v2 | ||
coverage: none | ||
|
||
- name: Install composer dependencies | ||
uses: nick-fields/retry@v2 | ||
with: | ||
timeout_minutes: 3 | ||
max_attempts: 5 | ||
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress | ||
|
||
- name: Run pest | ||
timeout-minutes: 2 | ||
run: ./vendor/bin/pest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./app</directory> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
if (! function_exists('getPackageName')) { | ||
function getPackageName(): string | ||
{ | ||
return 'Vapor Ignore'; | ||
} | ||
} | ||
|
||
if (! function_exists('getPackageVersion')) { | ||
function getPackageVersion(): string | ||
{ | ||
return Composer\InstalledVersions::getRootPackage()['pretty_version']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use AgeekDev\VaporIgnore\Commands\CleanIgnoredFilesCommand; | ||
use AgeekDev\VaporIgnore\Manifest; | ||
use AgeekDev\VaporIgnore\Path; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Tests\TestCase; | ||
|
||
use function PHPUnit\Framework\assertFileDoesNotExist; | ||
use function PHPUnit\Framework\assertStringContainsString; | ||
|
||
it('can run clean:ignored-files command', function (): void { | ||
Manifest::init([ | ||
'vendor' => [], | ||
]); | ||
|
||
/** | ||
* @var TestCase $this | ||
*/ | ||
$command = $this->resolveCommand(CleanIgnoredFilesCommand::class); | ||
|
||
$tester = new CommandTester($command); | ||
|
||
$tester->execute([ | ||
'command' => $command->getName(), | ||
]); | ||
|
||
$tester->assertCommandIsSuccessful(); | ||
|
||
assertFileDoesNotExist(Path::defaultManifest()); | ||
|
||
assertStringContainsString('Total Removed Files Size:', $tester->getDisplay()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
use AgeekDev\VaporIgnore\Commands\InitCommand; | ||
use AgeekDev\VaporIgnore\Manifest; | ||
use AgeekDev\VaporIgnore\Path; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Symfony\Component\Yaml\Yaml; | ||
use Tests\TestCase; | ||
|
||
use function PHPUnit\Framework\assertFileExists; | ||
use function PHPUnit\Framework\assertStringMatchesFormatFile; | ||
|
||
it('can run init command', function (): void { | ||
/** | ||
* @var TestCase $this | ||
*/ | ||
$command = $this->resolveCommand(InitCommand::class); | ||
|
||
$tester = new CommandTester($command); | ||
|
||
$tester->setInputs([ | ||
'no', | ||
]); | ||
|
||
$tester->execute([ | ||
'command' => $command->getName(), | ||
]); | ||
|
||
assertInitCommandRunPorperly($tester, Path::defaultManifest(), Yaml::dump(Manifest::freshConfiguration())); | ||
}); | ||
|
||
it('can run init command with force option', function (): void { | ||
touch(Path::defaultManifest()); | ||
|
||
/** | ||
* @var TestCase $this | ||
*/ | ||
$command = $this->resolveCommand(InitCommand::class); | ||
|
||
$tester = new CommandTester($command); | ||
|
||
$tester->setInputs([ | ||
'no', | ||
]); | ||
|
||
$tester->execute([ | ||
'command' => $command->getName(), | ||
'--force' => true, | ||
]); | ||
|
||
assertInitCommandRunPorperly($tester, Path::defaultManifest(), Yaml::dump(Manifest::freshConfiguration())); | ||
}); | ||
|
||
it('can run init command and override', function (): void { | ||
touch(Path::defaultManifest()); | ||
|
||
/** | ||
* @var TestCase $this | ||
*/ | ||
$command = $this->resolveCommand(InitCommand::class); | ||
|
||
$tester = new CommandTester($command); | ||
|
||
$tester->setInputs([ | ||
'yes', | ||
'no', | ||
]); | ||
|
||
$tester->execute([ | ||
'command' => $command->getName(), | ||
]); | ||
|
||
assertInitCommandRunPorperly($tester, Path::defaultManifest(), Yaml::dump(Manifest::freshConfiguration())); | ||
}); | ||
|
||
it('can run init command with custom manifest', function (): void { | ||
$customManifest = getcwd().'/vapor-ignore-test.yml'; | ||
|
||
/** | ||
* @var TestCase $this | ||
*/ | ||
$command = $this->resolveCommand(InitCommand::class); | ||
|
||
$tester = new CommandTester($command); | ||
|
||
$tester->setInputs([ | ||
'no', | ||
]); | ||
|
||
$tester->execute([ | ||
'command' => $command->getName(), | ||
'--manifest' => $customManifest, | ||
]); | ||
|
||
assertInitCommandRunPorperly($tester, $customManifest, Yaml::dump(Manifest::freshConfiguration())); | ||
|
||
removeFile($customManifest); | ||
}); | ||
|
||
it('can run init command and add clean command', function (): void { | ||
createVaporManifest(); | ||
|
||
/** | ||
* @var TestCase $this | ||
*/ | ||
$command = $this->resolveCommand(InitCommand::class); | ||
|
||
$tester = new CommandTester($command); | ||
|
||
$tester->setInputs([ | ||
'yes', | ||
]); | ||
|
||
$tester->execute([ | ||
'command' => $command->getName(), | ||
]); | ||
|
||
assertInitCommandRunPorperly($tester, Path::defaultManifest(), Yaml::dump(Manifest::freshConfiguration())); | ||
|
||
assertFileExists($vaporPath = Path::vaporManifest()); | ||
|
||
assertStringMatchesFormatFile($vaporPath, vaporManifestContentWithCleanCommand()); | ||
}); | ||
|
||
function assertInitCommandRunPorperly(CommandTester $tester, string $path, string $format): void | ||
{ | ||
$tester->assertCommandIsSuccessful(); | ||
|
||
assertFileExists($path); | ||
|
||
assertStringMatchesFormatFile($path, $format); | ||
} |
Oops, something went wrong.