Skip to content

Commit

Permalink
Small improvements
Browse files Browse the repository at this point in the history
- Unit Tests
- Wp Env
- Dependencies
- Psalm
  • Loading branch information
widoz committed Oct 27, 2023
1 parent a7ecbe3 commit 6a45a79
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"core": "WordPress/WordPress#6.2",
"core": "./vendor/roots/wordpress-no-content",
"themes": ["./.development/themes/test-theme"],
"env": {
"development": {
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"brain/monkey": "^2.6",
"mikey179/vfsstream": "^2.0",
"mockery/mockery": "^1.5",
"inpsyde/wp-stubs": "dev-main"
"php-stubs/wordpress-stubs": "~6.2.0",
"roots/wordpress-no-content": "~6.2.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "@inpsyde/gutenberg-versions-mirror",
"version": "1.0.0",
"description": "A lib that activate/deactivate a Gutenberg version depending on the Theme being activate",
"main": "index.js",
"repository": "git@github.com:inpsyde/gutenberg-versions-manager.git",
Expand All @@ -10,6 +9,7 @@
"@wordpress/env": "^8.10.0"
},
"scripts": {
"wp-env": "wp-env"
"wp-env:start": "wp-env start --environment=development",
"wp-env:stop": "wp-env stop"
}
}
10 changes: 8 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
strictBinaryOperands="true"
ignoreInternalFunctionFalseReturn="false"
ignoreInternalFunctionNullReturn="false"
findUnusedCode="true"
findUnusedBaselineEntry="true"
hideExternalErrors="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<directory name="src"/>

<ignoreFiles>
<directory name=".development"/>
</ignoreFiles>
</projectFiles>

<stubs>
<file name="vendor/inpsyde/wp-stubs/stubs/latest.php"/>
<file name="vendor/php-stubs/wordpress-stubs/wordpress-stubs.php"/>
</stubs>

<issueHandlers>
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/ServiceIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function boot(App\Container $c): bool
// phpcs:disable Inpsyde.CodeQuality.LineLength.TooLong
if ($this->isGutenbergPluginActive()) {
$this->notice->addNotice(
\__(
__(
'Gutenberg Version Manager cannot activate the Gutenberg plugin because a version of it is currently active. Please disable the Gutenberg plugin first.',
'gutenberg-versions-manager'
),
Expand Down
18 changes: 5 additions & 13 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
<?php // phpcs:disable
<?php

declare(strict_types=1);

(static function (string $libPath): void {
$vendorDir = "{$libPath}/vendor";
$phpTestDir = __DIR__;
$testsDir = \dirname($phpTestDir);
namespace Inpsyde\GutenbergVersionManager\Tests;

if (!\realpath($vendorDir)) {
die('Please install via Composer before running tests.');
}
require_once __DIR__ . '/functions.php';

/** @noinspection PhpIncludeInspection */
require_once "{$vendorDir}/autoload.php";
})(
\dirname(__DIR__)
);
bootstrap(\dirname(__DIR__));
18 changes: 18 additions & 0 deletions tests/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Inpsyde\GutenbergVersionManager\Tests;

function bootstrap(string $libPath): void
{
$vendorDir = "{$libPath}/vendor";
$phpTestDir = __DIR__;
$testsDir = \dirname($phpTestDir);

if (!\realpath($vendorDir)) {
die('Please install via Composer before running tests.');
}

require_once "{$vendorDir}/autoload.php";
}
1 change: 1 addition & 0 deletions tests/src/UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class UnitTestCase extends TestCase
'gutenberg.php' => '',
],
],
'theme-without-config-directory' => [],
],
];

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/Service/SupportedVersionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public function retrieve_empty_versions(): void
}

/**
* @test The `versions` entry does not exist and empty `versions` is returned
* @test Empty file content will still return an empty `versions` entry
*/
public function return_empty_versions_entry_if_entry_does_not_exists(): void
public function return_empty_versions_entry_if_file_content_is_empty(): void
{
$this->theme
->shouldReceive('get_template_directory')
Expand All @@ -70,13 +70,13 @@ public function return_empty_versions_entry_if_entry_does_not_exists(): void
}

/**
* @test Empty file content will still return an empty `versions` entry
* @test The config directory does not exists
*/
public function return_empty_versions_entry_if_file_content_is_empty(): void
public function return_empty_versions_entry_if_config_directory_does_not_exists(): void
{
$this->theme
->shouldReceive('get_template_directory')
->andReturn($this->themesPath('not-exists-versions-theme-name'));
->andReturn($this->themesPath('theme-without-config-directory'));

$supportedThemeVersions = Service\SupportedVersions::new();
$versions = $supportedThemeVersions->forTheme($this->theme);
Expand Down

0 comments on commit 6a45a79

Please sign in to comment.