Skip to content

Commit a703b34

Browse files
πŸ”§ Migrate unit tests to /tests/Unit
1 parent 4c18267 commit a703b34

13 files changed

+81
-32
lines changed

β€Žphpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit cacheResult="false" stopOnError="true" bootstrap="tests/bootstrap.php">
2+
<phpunit cacheResult="false" stopOnError="true" bootstrap="./tests/Unit/Bootstrap.php">
33
<testsuites>
44
<testsuite name="Tests">
55
<directory>tests/</directory>

β€Žtests/Unit/Bootstrap.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright (c) Dimitri BOUTEILLE (https://github.com/dimitriBouteille)
4+
* See LICENSE.txt for license details.
5+
*
6+
* Author: Dimitri BOUTEILLE <bonjour@dimitri-bouteille.fr>
7+
*/
8+
9+
namespace Dbout\WpRestApi\Tests\Unit;
10+
11+
class Bootstrap
12+
{
13+
private static ?self $instance = null;
14+
15+
protected string $wpDirectory = '';
16+
17+
public function __construct()
18+
{
19+
$this->wpDirectory = __DIR__ . '/../../web/wordpress';
20+
$this->initConstants();
21+
$this->loadFiles();
22+
}
23+
24+
/**
25+
* @return self
26+
*/
27+
public static function run(): self
28+
{
29+
if (!self::$instance instanceof Bootstrap) {
30+
self::$instance = new self();
31+
}
32+
33+
return self::$instance;
34+
}
35+
36+
/**
37+
* @return void
38+
*/
39+
protected function initConstants(): void
40+
{
41+
define('ABSPATH', sprintf('%s/', $this->wpDirectory));
42+
define('WP_DEBUG', false);
43+
define('WP_CONTENT_DIR', '/');
44+
define('WP_DEBUG_LOG', false);
45+
define('WP_PLUGIN_DIR', './');
46+
define('WPMU_PLUGIN_DIR', './');
47+
define('EMPTY_TRASH_DAYS', 30 * 86400);
48+
define('SCRIPT_DEBUG', false);
49+
define('WP_LANG_DIR', './');
50+
define('WPINC', 'wp-includes');
51+
}
52+
53+
/**
54+
* @return void
55+
*/
56+
protected function loadFiles(): void
57+
{
58+
$paths = [
59+
'/load.php',
60+
'/functions.php',
61+
'/plugin.php',
62+
'/class-wp-http-response.php',
63+
'/rest-api.php',
64+
'/rest-api/class-wp-rest-server.php',
65+
'/rest-api/class-wp-rest-response.php',
66+
'/rest-api/class-wp-rest-request.php',
67+
'/class-wp-error.php',
68+
];
69+
70+
foreach ($paths as $path) {
71+
require sprintf('%s/wp-includes/%s', $this->wpDirectory, $path);
72+
}
73+
}
74+
}
75+
76+
Bootstrap::run();

β€Žtests/Helpers/ParserTest.php renamed to β€Žtests/Unit/Helpers/ParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Author: Dimitri BOUTEILLE <bonjour@dimitri-bouteille.fr>
77
*/
88

9-
namespace Dbout\WpRestApi\Tests\Helpers;
9+
namespace Dbout\WpRestApi\Tests\Unit\Helpers;
1010

1111
use Dbout\WpRestApi\Helpers\Parser;
1212
use PHPUnit\Framework\TestCase;

β€Žtests/Wrappers/PermissionWrapperTest.php renamed to β€Žtests/Unit/Wrappers/PermissionWrapperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22
/**
3-
* Copyright (c) 2024 Dimitri BOUTEILLE (https://github.com/dimitriBouteille)
3+
* Copyright (c) Dimitri BOUTEILLE (https://github.com/dimitriBouteille)
44
* See LICENSE.txt for license details.
55
*
66
* Author: Dimitri BOUTEILLE <bonjour@dimitri-bouteille.fr>
77
*/
88

9-
namespace Dbout\WpRestApi\Tests\Wrappers;
9+
namespace Dbout\WpRestApi\Tests\Unit\Wrappers;
1010

1111
use Dbout\WpRestApi\RouteAction;
1212
use Dbout\WpRestApi\Wrappers\PermissionWrapper;

β€Žtests/Wrappers/RestWrapperTest.php renamed to β€Žtests/Unit/Wrappers/RestWrapperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Author: Dimitri BOUTEILLE <bonjour@dimitri-bouteille.fr>
77
*/
88

9-
namespace Dbout\WpRestApi\Tests\Wrappers;
9+
namespace Dbout\WpRestApi\Tests\Unit\Wrappers;
1010

1111
use Dbout\WpRestApi\RouteAction;
1212
use Dbout\WpRestApi\Tests\fixtures\RouteWithException;

β€Žtests/bootstrap.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
Β (0)