Skip to content

Commit

Permalink
convert to PHPUnit 10
Browse files Browse the repository at this point in the history
  • Loading branch information
LordSimal committed May 30, 2023
1 parent ed175b8 commit 9195679
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/tools
/vendor
/.idea/
/.phpunit.result.cache
/.phpunit.cache
tests/test_app/App/Model/Table/CommentsTable.php
tests/test_app/App/Controller/ProductVersionsController.php
tests/test_app/App/Controller/ProductsController.php
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require-dev": {
"cakephp/cakephp-codesniffer": "5.x-dev",
"phpunit/phpunit": "^9.5.19",
"phpunit/phpunit": "^10.1.0",
"cakephp/debug_kit": "5.x-dev",
"cakephp/plugin-installer": "^1.3"
},
Expand Down
21 changes: 11 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
processIsolation="false"
stopOnFailure="false"
cacheDirectory=".phpunit.cache"
bootstrap="tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
>
<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="bake">
Expand All @@ -14,14 +15,14 @@
</testsuites>

<extensions>
<extension class="Cake\TestSuite\Fixture\PHPUnitExtension"/>
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
</extensions>

<coverage>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
</source>

<php>
<env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);

namespace TestBake\Test\TestCase\Middleware;

use Cake\TestSuite\TestCase;

/**
* TestBake\Middleware\ExampleMiddleware Test Case
*/
class ExampleMiddlewareTest extends TestCase
{
/**
* Test subject
*
* @var \TestBake\Middleware\ExampleMiddleware
*/
protected $Example;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);

namespace TestBake\Test\TestCase\Model\Table;

use Cake\TestSuite\TestCase;
use TestBake\Model\Table\BakeArticlesTable;

/**
* TestBake\Model\Table\BakeArticlesTable Test Case
*/
class BakeArticlesTableTest extends TestCase
{
/**
* Test subject
*
* @var \TestBake\Model\Table\BakeArticlesTable
*/
protected $BakeArticles;

/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('BakeArticles') ? [] : ['className' => BakeArticlesTable::class];
$this->BakeArticles = $this->getTableLocator()->get('BakeArticles', $config);
}

/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->BakeArticles);

parent::tearDown();
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/Command/AllCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function testExecuteWithPrefix()
}

/**
* Test docblock @uses generated for test methods
* Test docblock @ uses generated for test methods
*
* @return void
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/CommandCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function testBakePlugin()
}

/**
* Test docblock @uses generated for test methods
* Test docblock @ uses generated for test methods
*
* @return void
*/
Expand All @@ -123,7 +123,7 @@ public function testGenerateUsesDocBlock()
}

/**
* Test docblock @uses generated for test methods
* Test docblock @ uses generated for test methods
* Plugin command
*
* @return void
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Command/SimpleBakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function testBakePlugin()
*
* @return string[][]
*/
public function subclassProvider()
public static function subclassProvider()
{
return [
['Bake\Command\BehaviorCommand'],
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/TestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ public function testMapType($original, $expected)
}

/**
* Test docblock @uses generated for test methods
* Test docblock @ uses generated for test methods
*
* @return void
*/
Expand All @@ -740,7 +740,7 @@ public function testGenerateUsesDocBlockController()
}

/**
* Test docblock @uses generated for test methods
* Test docblock @ uses generated for test methods
*
* @return void
*/
Expand Down
32 changes: 0 additions & 32 deletions tests/TestCase/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
use Cake\Routing\Router;
use Cake\TestSuite\StringCompareTrait;
use Cake\TestSuite\TestCase as BaseTestCase;
use PHPUnit\Framework\Constraint\FileExists;
use PHPUnit\Framework\Constraint\LogicalNot;
use PHPUnit\Framework\Constraint\RegularExpression;

abstract class TestCase extends BaseTestCase
{
Expand Down Expand Up @@ -84,21 +81,6 @@ protected function _loadTestPlugin($name)
]);
}

/**
* Asserts that a string matches a given regular expression.
*
* @param string $pattern Regex pattern
* @param string $string String to test
* @param string $message Message
* @return void
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
* @codeCoverageIgnore
*/
public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
{
static::assertThat($string, new RegularExpression($pattern), $message);
}

/**
* Assert that a list of files exist.
*
Expand All @@ -112,20 +94,6 @@ protected function assertFilesExist(array $files, $message = '')
}
}

/**
* Asserts that a file does not exist.
*
* @param string $filename Filename
* @param string $message Message
* @return void
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
* @codeCoverageIgnore
*/
public static function assertFileDoesNotExist(string $filename, string $message = ''): void
{
static::assertThat($filename, new LogicalNot(new FileExists()), $message);
}

/**
* Assert that a file contains a substring
*
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/View/Helper/BakeHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testAliasExtractorFilteredHasMany()
]);
$this->BakeHelper = $this->getMockBuilder('Bake\View\Helper\BakeHelper')
->disableOriginalConstructor()
->setMethods(['_filterHasManyAssociationsAliases'])
->onlyMethods(['_filterHasManyAssociationsAliases'])
->getMock();
$this->BakeHelper->expects($this->once())
->method('_filterHasManyAssociationsAliases')
Expand Down

0 comments on commit 9195679

Please sign in to comment.