From 79029f9df01dcbcdce07a908b0e21f585b1a2169 Mon Sep 17 00:00:00 2001 From: peter279k Date: Sun, 2 Sep 2018 03:15:31 +0800 Subject: [PATCH] Intialize Util Composer, Git and Metadata tests --- tests/Util/ComposerTest.php | 75 ++++++++++++++++++++++++++++++++++++ tests/Util/GitTest.php | 56 +++++++++++++++++++++++++++ tests/Util/InflectorTest.php | 7 ++++ tests/Util/MetadataTest.php | 61 +++++++++++++++++++++++++++++ tests/Util/PathTest.php | 7 ++++ 5 files changed, 206 insertions(+) create mode 100644 tests/Util/ComposerTest.php create mode 100644 tests/Util/GitTest.php create mode 100644 tests/Util/MetadataTest.php diff --git a/tests/Util/ComposerTest.php b/tests/Util/ComposerTest.php new file mode 100644 index 0000000..d75d19a --- /dev/null +++ b/tests/Util/ComposerTest.php @@ -0,0 +1,75 @@ + + * + * + * Licensed under MIT license. + */ + +namespace Ahc\Phint\Test; + +use Ahc\Phint\Util\Composer; +use PHPUnit\Framework\TestCase; + +class ComposerTest extends TestCase +{ + public function testCreateProjectOnWithoutComposerBinary() + { + $composer = new Composer; + $composer->withWorkDir(sys_get_temp_dir()); + $result = $composer->createProject('project-name', 'app-name'); + + $this->assertInstanceOf(Composer::class, $result); + $this->assertFalse($result->successful()); + } + + public function testInstallOnWithoutComposerBinary() + { + $composer = new Composer; + $composer->withWorkDir(sys_get_temp_dir()); + $result = $composer->install(); + + $this->assertInstanceOf(Composer::class, $result); + $this->assertFalse($result->successful()); + } + + public function testUpdateOnWithoutComposerBinary() + { + $composer = new Composer; + $composer->withWorkDir(sys_get_temp_dir()); + $result = $composer->update(); + + $this->assertInstanceOf(Composer::class, $result); + $this->assertFalse($result->successful()); + } + + public function testDumpAutoloadOnWithoutComposerBinary() + { + $composer = new Composer; + $composer->withWorkDir(sys_get_temp_dir()); + $result = $composer->dumpAutoload(); + + $this->assertInstanceOf(Composer::class, $result); + $this->assertFalse($result->successful()); + } + + public function testConfigOnNullDefaultValue() + { + $composer = new Composer; + $composer->withWorkDir(sys_get_temp_dir()); + + $this->assertNull($composer->config('name')); + } + + public function testConfigOnDefaultValue() + { + copy(__DIR__ . '/../../composer.json', sys_get_temp_dir() . '/composer.json'); + $composer = new Composer; + $composer->withWorkDir(sys_get_temp_dir()); + + $this->assertSame('app/name', $composer->config('name.license', 'app/name')); + } +} diff --git a/tests/Util/GitTest.php b/tests/Util/GitTest.php new file mode 100644 index 0000000..3458d2b --- /dev/null +++ b/tests/Util/GitTest.php @@ -0,0 +1,56 @@ + + * + * + * Licensed under MIT license. + */ + +namespace Ahc\Phint\Test; + +use Ahc\Phint\Util\Git; +use PHPUnit\Framework\TestCase; + +class GitTest extends TestCase +{ + public function testGetConfig() + { + $git = new Git; + + $this->assertArraySubset([ + 'core.repositoryformatversion' => '0', + 'core.filemode' => 'true', + 'core.bare' => 'false', + 'core.logallrefupdates' => 'true', + 'remote.origin.url' => 'https://github.com/adhocore/phint.git', + 'remote.origin.fetch' => '+refs/heads/master:refs/remotes/origin/master', + '' => '', + ], $git->getConfig()); + } + + public function testGetConfigOnSpecificKey() + { + $git = new Git; + + $this->assertSame('false', $git->getConfig('core.bare')); + } + + public function testInit() + { + $git = new Git(); + + $this->assertInstanceOf(Git::class, $git->init()); + $this->assertTrue($git->successful()); + } + + public function testAddRemote() + { + $git = new Git(); + + $this->assertInstanceOf(Git::class, $git->addRemote('adhocore', 'phint')); + $this->assertFalse($git->successful()); + } +} diff --git a/tests/Util/InflectorTest.php b/tests/Util/InflectorTest.php index 625c486..778983c 100644 --- a/tests/Util/InflectorTest.php +++ b/tests/Util/InflectorTest.php @@ -23,6 +23,13 @@ public function testStuldyCase() $this->assertEquals('ThisWillBeUcwordString', $inflector->stuldyCase('this-will-be-ucword-string')); } + public function testSnakeCase() + { + $inflector = new Inflector; + + $this->assertEquals('this_will_be_snake_case_string', $inflector->snakeCase('this will be snake case string')); + } + public function testWords() { $inflector = new Inflector; diff --git a/tests/Util/MetadataTest.php b/tests/Util/MetadataTest.php new file mode 100644 index 0000000..3da8730 --- /dev/null +++ b/tests/Util/MetadataTest.php @@ -0,0 +1,61 @@ + + * + * + * Licensed under MIT license. + */ + +namespace Ahc\Phint\Test; + +use Ahc\Phint\Util\Metadata; +use PHPUnit\Framework\TestCase; + +class MetadataTest extends TestCase +{ + public function testForClass() + { + $metaData = new Metadata; + $result = $metaData->forClass(Metadata::class); + + $this->assertArraySubset([ + 'namespace' => 'Ahc\Phint\Util', + 'classFqcn' => 'Ahc\Phint\Util\Metadata', + 'name' => 'Metadata', + 'className' => 'Metadata', + 'isTrait' => false, + 'isAbstract' => false, + 'isInterface' => false, + 'newable' => true, + 'title' => null, + 'texts' => [], + 'methods' => [], + 'name' => 'Metadata', + ], $result); + } + + public function testForMethod() + { + $metaData = new Metadata; + $result = $metaData->forMethod(Metadata::class, 'forClass'); + + $this->assertSame([ + 'name' => 'forClass', + 'inClass' => 'Ahc\Phint\Util\Metadata', + 'isStatic' => false, + 'isFinal' => false, + 'isPublic' => true, + 'isAbstract' => false, + 'maybeMagic' => false, + 'title' => null, + 'texts' => [], + 'params' => [ + 'string $classFqcn', + ], + 'return' => 'array', + ], $result); + } +} diff --git a/tests/Util/PathTest.php b/tests/Util/PathTest.php index a940851..d99fe8f 100644 --- a/tests/Util/PathTest.php +++ b/tests/Util/PathTest.php @@ -81,6 +81,13 @@ public function testGetPhintPath() $this->assertContains('/home', $path->getPhintPath('/fixtures')); } + public function testGetPhintPathOnEmptySubPath() + { + $path = new Path; + + $this->assertContains('', $path->getPhintPath()); + } + public function testWriteFile() { $writeFilePath = __DIR__ . '/../fixtures/write_file.txt';