Skip to content

Use phpunit 10 in Create Framework tutorial #20929

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

Open
wants to merge 1 commit into
base: 6.4
Choose a base branch
from
Open
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
24 changes: 12 additions & 12 deletions create_framework/unit_testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

.. code-block:: terminal

$ composer require --dev phpunit/phpunit:^9.6
$ composer require --dev phpunit/phpunit:^10.0

Then, create a PHPUnit configuration file in ``example.com/phpunit.xml.dist``:

Expand All @@ -21,16 +21,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<coverage processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</source>

<testsuites>
<testsuite name="Test Suite">
Expand Down Expand Up @@ -77,7 +77,7 @@
// example.com/tests/Simplex/Tests/FrameworkTest.php
namespace Simplex\Tests;

use PHPUnit\Framework\TestCase;

Check failure on line 80 in create_framework/unit_testing.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Missing class] Class, interface or trait with name "PHPUnit\Framework\TestCase" does not exist
use Simplex\Framework;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
Expand All @@ -103,12 +103,12 @@
$matcher
->expects($this->once())
->method('match')
->will($this->throwException($exception))
->willThrowException($exception)
;
$matcher
->expects($this->once())
->method('getContext')
->will($this->returnValue($this->createMock(Routing\RequestContext::class)))
->willReturn($this->createMock(Routing\RequestContext::class))
;
$controllerResolver = $this->createMock(ControllerResolverInterface::class);
$argumentResolver = $this->createMock(ArgumentResolverInterface::class);
Expand Down Expand Up @@ -161,16 +161,16 @@
$matcher
->expects($this->once())
->method('match')
->will($this->returnValue([
->willReturn([
'_route' => 'is_leap_year/{year}',
'year' => '2000',
'_controller' => [new LeapYearController(), 'index'],
]))
])
;
$matcher
->expects($this->once())
->method('getContext')
->will($this->returnValue($this->createMock(Routing\RequestContext::class)))
->willReturn($this->createMock(Routing\RequestContext::class))
;
$controllerResolver = new ControllerResolver();
$argumentResolver = new ArgumentResolver();
Expand All @@ -194,7 +194,7 @@

$ ./vendor/bin/phpunit --coverage-html=cov/

Open ``example.com/cov/src/Simplex/Framework.php.html`` in a browser and check
Open ``example.com/cov/Simplex/Framework.php.html`` in a browser and check
that all the lines for the Framework class are green (it means that they have
been visited when the tests were executed).

Expand All @@ -212,6 +212,6 @@
Now that we are confident (again) about the code we have written, we can
safely think about the next batch of features we want to add to our framework.

.. _`PHPUnit`: https://docs.phpunit.de/en/9.6/
.. _`test doubles`: https://docs.phpunit.de/en/9.6/test-doubles.html
.. _`PHPUnit`: https://docs.phpunit.de/en/10.0/
.. _`test doubles`: https://docs.phpunit.de/en/10.0/test-doubles.html
.. _`XDebug`: https://xdebug.org/
Loading