diff --git a/phpunit.xml b/phpunit.xml index f255df3..1e26142 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,12 +1,13 @@ - + + + + + src + + tests - - - src - - diff --git a/spec/dependencies/dependency_types.spec.php b/spec/dependencies/dependency_types.spec.php new file mode 100644 index 0000000..1aae91d --- /dev/null +++ b/spec/dependencies/dependency_types.spec.php @@ -0,0 +1,9 @@ +toBe(['themes', 'plugins']); + }); + }); +}); diff --git a/src/Dependencies/DependencyTypes.php b/src/Dependencies/DependencyTypes.php new file mode 100644 index 0000000..e3de5af --- /dev/null +++ b/src/Dependencies/DependencyTypes.php @@ -0,0 +1,16 @@ +isErr()) { return $resultLoad; } - $dependencyTypes = ['themes', 'plugins']; $git = new \Dxw\Whippet\Git\Git($this->dir); $results = []; - foreach ($dependencyTypes as $type) { + foreach (DependencyTypes::getDependencyTypes() as $type) { foreach ($this->lockFile->getDependencies($type) as $dep) { $result = $git::tag_for_commit($dep['src'], $dep['revision']); if ($result->isErr()) { diff --git a/src/Dependencies/Installer.php b/src/Dependencies/Installer.php index f837db2..e76475c 100644 --- a/src/Dependencies/Installer.php +++ b/src/Dependencies/Installer.php @@ -28,7 +28,7 @@ public function installAll() $dependencies = []; - foreach (['themes', 'plugins'] as $type) { + foreach (DependencyTypes::getDependencyTypes() as $type) { $dependencies[$type] = $this->lockFile->getDependencies($type); } diff --git a/src/Dependencies/Updater.php b/src/Dependencies/Updater.php index 37cba7e..d7977dc 100644 --- a/src/Dependencies/Updater.php +++ b/src/Dependencies/Updater.php @@ -57,7 +57,7 @@ public function updateAll() $allDependencies = []; - foreach (['themes', 'plugins'] as $type) { + foreach (DependencyTypes::getDependencyTypes() as $type) { $allDependencies[$type] = $this->jsonFile->getDependencies($type); } @@ -133,7 +133,7 @@ private function updateHash() private function createGitIgnore() { - foreach (['themes', 'plugins'] as $type) { + foreach (DependencyTypes::getDependencyTypes() as $type) { foreach ($this->jsonFile->getDependencies($type) as $dep) { $this->addDependencyToIgnoresArray($type, $dep['name']); } @@ -151,7 +151,7 @@ private function loadGitignore() } // Iterate through locked dependencies and remove from gitignore - foreach (['themes', 'plugins'] as $type) { + foreach (DependencyTypes::getDependencyTypes() as $type) { foreach ($this->lockFile->getDependencies($type) as $dep) { $line = $this->getGitignoreDependencyLine($type, $dep['name']); $index = array_search($line, $this->ignores); diff --git a/src/Dependencies/Validator.php b/src/Dependencies/Validator.php index 17ab56d..209638e 100644 --- a/src/Dependencies/Validator.php +++ b/src/Dependencies/Validator.php @@ -46,7 +46,7 @@ public function validate(bool $enforceRefs = false) // Check that entries in whippet.json // match entries in whippet.lock - foreach (['themes', 'plugins'] as $type) { + foreach (DependencyTypes::getDependencyTypes() as $type) { $whippetJsonDependencies = $whippetJson->getDependencies($type); $whippetLockDependencies = $whippetLock->getDependencies($type); if (count($whippetJsonDependencies) !== count($whippetLockDependencies)) { diff --git a/src/Git/Gitignore.php b/src/Git/Gitignore.php index 9c6c97b..b37fffb 100644 --- a/src/Git/Gitignore.php +++ b/src/Git/Gitignore.php @@ -45,7 +45,7 @@ public function save_ignores($ignores) private function ensure_closing_newline($ignores) { $index_of_last_line = count($ignores) - 1; - $last_line = $ignores[$index_of_last_line]; + $last_line = $index_of_last_line >= 0 ? $ignores[$index_of_last_line] : 0; $last_character = substr($last_line, -1); if ($last_character != "\n") { diff --git a/tests/services/inspection_checker_test.php b/tests/services/inspection_checker_test.php index 5f0c187..ba3022e 100644 --- a/tests/services/inspection_checker_test.php +++ b/tests/services/inspection_checker_test.php @@ -35,7 +35,8 @@ public function testPluginCallsAPI() 'revision' => '123456', ]; $checker = new \Dxw\Whippet\Services\InspectionChecker($api); - $checker->check('plugins', $my_plugin); + $result = $checker->check('plugins', $my_plugin); + $this->assertFalse($result->isErr()); } public function testPluginWithNoInspectionsGeneratesMessage() diff --git a/tests/services/inspections_api_test.php b/tests/services/inspections_api_test.php index 3221c82..6e43bfe 100644 --- a/tests/services/inspections_api_test.php +++ b/tests/services/inspections_api_test.php @@ -16,7 +16,9 @@ public function testCallsApi() ->andReturn(\Result\Result::ok([])); $api = new \Dxw\Whippet\Services\InspectionsApi('https://advisories.dxw.com', '/wp-json/v1/inspections/', $json_api); - $api->getInspections('my-plugin'); + $result = $api->getInspections('my-plugin'); + $this->assertFalse($result->isErr()); + $this->assertEquals([], $result->unwrap()); } public function testNoInspections() diff --git a/tests/services/json_api_test.php b/tests/services/json_api_test.php index f4a3dd0..3adbb90 100644 --- a/tests/services/json_api_test.php +++ b/tests/services/json_api_test.php @@ -16,7 +16,9 @@ public function testCallsApi() ->andReturn(\Result\Result::ok('[]')); $api = new \Dxw\Whippet\Services\JsonApi($base_api); - $api->get('http://apisite.com/api/endpoint'); + $result = $api->get('http://apisite.com/api/endpoint'); + $this->assertFalse($result->isErr()); + $this->assertEquals([], $result->unwrap()); } public function testEmptyResponse()