-
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
Showing
20 changed files
with
234 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,37 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Souplette\Chicot\Command; | ||
|
||
use ReflectionExtension; | ||
use Souplette\Chicot\StubsGenerator; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
final class GenerateStubsCommand extends Command | ||
{ | ||
#[\Override] | ||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Generates IDE stubs for an extension.') | ||
->addArgument('extension', InputArgument::REQUIRED, 'The name of the extension') | ||
->addArgument('output-file', InputArgument::OPTIONAL, 'The output file path') | ||
; | ||
} | ||
|
||
#[\Override] | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$ext = new ReflectionExtension($input->getArgument('extension')); | ||
$code = StubsGenerator::generate($ext); | ||
if ($outputPath = $input->getArgument('output-file')) { | ||
$file = new \SplFileObject($outputPath, 'w'); | ||
$file->fwrite($code); | ||
} else { | ||
$output->writeln($code); | ||
} | ||
return Command::SUCCESS; | ||
} | ||
} |
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,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Souplette\Chicot\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
final class ListExtensionsCommand extends Command | ||
{ | ||
#[\Override] | ||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Lists installed extensions.') | ||
; | ||
} | ||
|
||
#[\Override] | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
foreach (get_loaded_extensions() as $name) { | ||
$output->writeln($name); | ||
} | ||
return Command::SUCCESS; | ||
} | ||
} |
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,39 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Souplette\Chicot\Tests\Command; | ||
|
||
use PHPUnit\Framework\Assert; | ||
use PHPUnit\Framework\TestCase; | ||
use Souplette\Chicot\Command\GenerateStubsCommand; | ||
use Souplette\Chicot\Tests\TemporaryFileGuard; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
final class GenerateStubsTest extends TestCase | ||
{ | ||
public function testItPrintStubsToStdout(): void | ||
{ | ||
$cmd = new GenerateStubsCommand('stub'); | ||
$tester = new CommandTester($cmd); | ||
// json extension is a PHPUnit dependency, so should always be present in this environment. | ||
$tester->execute(['extension' => 'json']); | ||
$tester->assertCommandIsSuccessful(); | ||
$output = $tester->getDisplay(); | ||
Assert::assertStringContainsString('function json_encode(', $output); | ||
} | ||
|
||
public function testItWritesStubsToFile(): void | ||
{ | ||
$guard = new TemporaryFileGuard(); | ||
$cmd = new GenerateStubsCommand('stub'); | ||
$tester = new CommandTester($cmd); | ||
// json extension is a PHPUnit dependency, so should always be present in this environment. | ||
$tester->execute([ | ||
'extension' => 'json', | ||
'output-file' => $guard->path, | ||
]); | ||
$tester->assertCommandIsSuccessful(); | ||
|
||
Assert::assertFileExists($guard->path); | ||
Assert::assertStringContainsString('function json_encode(', $guard->getContents()); | ||
} | ||
} |
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 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Souplette\Chicot\Tests\Command; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Souplette\Chicot\Command\ListExtensionsCommand; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
final class ListExtensionsTest extends TestCase | ||
{ | ||
public function testListExtensions(): void | ||
{ | ||
$cmd = new ListExtensionsCommand(); | ||
$tester = new CommandTester($cmd); | ||
$tester->execute([]); | ||
$tester->assertCommandIsSuccessful(); | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
tests/ExtensionAttributesTest.php → tests/Generator/AttributesTest.php
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
5 changes: 3 additions & 2 deletions
5
tests/ExtensionConstantsTest.php → tests/Generator/ConstantsTest.php
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
3 changes: 2 additions & 1 deletion
3
tests/ExtensionInterfaceTest.php → tests/Generator/ExtensionInterfaceTest.php
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
Oops, something went wrong.