Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/small fixes #261

Merged
merged 4 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<phpunit bootstrap="tests/Helpers.php" backupGlobals="false" colors="true">
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/Helpers.php" backupGlobals="false" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="unit_and_integration">
<directory suffix="_test.php">tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
9 changes: 9 additions & 0 deletions spec/dependencies/dependency_types.spec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

describe(\Dxw\Whippet\Dependencies\DependencyTypes::class, function () {
context("getDependencyTypes()", function () {
it('returns a list of dependencies as strings', function () {
expect(\Dxw\Whippet\Dependencies\DependencyTypes::getDependencyTypes())->toBe(['themes', 'plugins']);
});
});
});
16 changes: 16 additions & 0 deletions src/Dependencies/DependencyTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Dxw\Whippet\Dependencies;

class DependencyTypes
{
public const PLUGINS = 'plugins';
public const THEMES = 'themes';


public static function getDependencyTypes()
{

return [DependencyTypes::THEMES, DependencyTypes::PLUGINS];
}
}
3 changes: 1 addition & 2 deletions src/Dependencies/Describer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ public function describe()
if ($resultLoad->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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Dependencies/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function installAll()

$dependencies = [];

foreach (['themes', 'plugins'] as $type) {
foreach (DependencyTypes::getDependencyTypes() as $type) {
$dependencies[$type] = $this->lockFile->getDependencies($type);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Dependencies/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function updateAll()

$allDependencies = [];

foreach (['themes', 'plugins'] as $type) {
foreach (DependencyTypes::getDependencyTypes() as $type) {
$allDependencies[$type] = $this->jsonFile->getDependencies($type);
}

Expand Down Expand Up @@ -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']);
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Dependencies/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Git/Gitignore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
3 changes: 2 additions & 1 deletion tests/services/inspection_checker_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion tests/services/inspections_api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion tests/services/json_api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading