-
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.
- Loading branch information
1 parent
ef6c45b
commit ef8bdd7
Showing
11 changed files
with
372 additions
and
5 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,38 @@ | ||
name: Unit Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: ~ | ||
|
||
jobs: | ||
unit_tests: | ||
strategy: | ||
matrix: | ||
php: | ||
- '8.2' | ||
- '8.3' | ||
|
||
runs-on: ubuntu-latest | ||
|
||
name: "PHP ${{ matrix.php }} tests" | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: pcov | ||
|
||
- uses: "ramsey/composer-install@v2" | ||
|
||
- run: ./vendor/bin/phpunit | ||
|
||
- uses: codecov/codecov-action@v2 | ||
with: | ||
name: "phpunit-php${{ matrix.php }}" | ||
flags: phpunit | ||
fail_ci_if_error: true | ||
continue-on-error: true |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
coverage/ | ||
vendor/ | ||
.idea/ | ||
tests/generated/ | ||
composer.lock | ||
clover.xml | ||
.phpunit.result.cache |
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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace XGraphQL\Codegen\Test\Console; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use XGraphQL\Codegen\Console\CodegenCommand; | ||
use XGraphQL\Codegen\Generator; | ||
|
||
class CodegenCommandTest extends TestCase | ||
{ | ||
public function testRunCommand() | ||
{ | ||
$command = new CodegenCommand(); | ||
$command->setGenerators( | ||
[ | ||
'test' => new Generator( | ||
'', | ||
__DIR__ . '/../fixtures/source_dir', | ||
__DIR__ . '/../generated', | ||
) | ||
] | ||
); | ||
$tester = new CommandTester($command); | ||
$tester->execute([]); | ||
|
||
$tester->assertCommandIsSuccessful(); | ||
$this->assertMatchesRegularExpression('~Generated PHP code for `test` successful~', $tester->getDisplay()); | ||
} | ||
|
||
public function testRunCommandWithEmptyGenerators() | ||
{ | ||
$command = new CodegenCommand(); | ||
$command->setGenerators([]); | ||
$tester = new CommandTester($command); | ||
$tester->execute([]); | ||
|
||
$tester->assertCommandIsSuccessful(); | ||
$this->assertEmpty($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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace XGraphQL\Codegen\Test\Console; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use XGraphQL\Codegen\Console\InitConfigCommand; | ||
|
||
class InitConfigCommandTest extends TestCase | ||
{ | ||
private const CONFIG_FILE = __DIR__ . '/../generated/config.php'; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
@mkdir(__DIR__ . '../generated'); | ||
@unlink(self::CONFIG_FILE); | ||
} | ||
|
||
public function testInitConfig(): void | ||
{ | ||
$this->assertFileDoesNotExist(self::CONFIG_FILE); | ||
|
||
$command = new InitConfigCommand(); | ||
$command->setConfigFile(self::CONFIG_FILE); | ||
$tester = new CommandTester($command); | ||
$tester->execute([]); | ||
|
||
$tester->assertCommandIsSuccessful(); | ||
$this->assertFileExists(self::CONFIG_FILE); | ||
$this->assertFileEquals(__DIR__ . '/../../resources/config.template.php', self::CONFIG_FILE); | ||
} | ||
|
||
public function testInitConfigExisted(): void | ||
{ | ||
touch(self::CONFIG_FILE); | ||
$this->assertFileExists(self::CONFIG_FILE); | ||
|
||
$command = new InitConfigCommand(); | ||
$command->setConfigFile(self::CONFIG_FILE); | ||
$tester = new CommandTester($command); | ||
$tester->execute([]); | ||
|
||
$tester->assertCommandIsSuccessful(); | ||
$this->assertEmpty(file_get_contents(self::CONFIG_FILE)); | ||
|
||
$tester->setInputs(['yes']); | ||
$tester->execute([]); | ||
|
||
$this->assertFileEquals(__DIR__ . '/../../resources/config.template.php', self::CONFIG_FILE); | ||
} | ||
} |
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,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace XGraphQL\Codegen\Test; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use XGraphQL\Codegen\Exception\RuntimeException; | ||
use XGraphQL\Codegen\Generator; | ||
|
||
class GeneratorTest extends TestCase | ||
{ | ||
private const GENERATED_PATH = __DIR__ . '/generated'; | ||
|
||
protected function setUp(): void | ||
{ | ||
$fileSystem = new Filesystem(); | ||
|
||
$fileSystem->remove(self::GENERATED_PATH); | ||
$fileSystem->mkdir(self::GENERATED_PATH); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testUseInvalidSourcePathWillThrowException(): void | ||
{ | ||
$generator = new Generator('', '', ''); | ||
|
||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessageMatches('~does not exists or not have read permission$~'); | ||
|
||
$generator->generate(); | ||
} | ||
|
||
public function testEmptyQueryWillThrowException(): void | ||
{ | ||
$generator = new Generator('', __DIR__ . '/fixtures/empty_source_dir', ''); | ||
|
||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessageMatches('~^Not found any query~'); | ||
|
||
$generator->generate(); | ||
} | ||
|
||
public function testInvalidDestinationPathWillThrowException(): void | ||
{ | ||
$generator = new Generator('', __DIR__ . '/fixtures/source_dir', ''); | ||
|
||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessageMatches('~exists and have write permission$~'); | ||
|
||
$generator->generate(); | ||
} | ||
|
||
public function testCanGenerate(): void | ||
{ | ||
$queryName = uniqid('Q'); | ||
$generator = new Generator( | ||
'', | ||
__DIR__ . '/fixtures/source_dir', | ||
self::GENERATED_PATH, | ||
$queryName, | ||
); | ||
$generator->generate(); | ||
|
||
$this->assertFileExists(sprintf('%s/%s.php', self::GENERATED_PATH, $queryName)); | ||
$this->assertFileExists(sprintf('%s/%s/GetUsersTrait.php', self::GENERATED_PATH, $queryName)); | ||
$this->assertFileExists(sprintf('%s/%s/GetCountryTrait.php', self::GENERATED_PATH, $queryName)); | ||
} | ||
} |
Oops, something went wrong.