Skip to content

Commit 89a8f61

Browse files
authored
Upgrade to phpunit 10 (#26)
* Upgrade to phpunit 10 * Bump up php to 8.1 * Upgrade phpunit config * Use jobs_default variable * Fix tests * Remove unused code * Ignore *.cache files and directories * Add minimum coverage
1 parent 69066af commit 89a8f61

8 files changed

Lines changed: 43 additions & 62 deletions

File tree

.circleci/config.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
version: 2.1
22

33
orbs:
4-
ci: bigcommerce/internal@volatile
54
php: bigcommerce/internal-php@volatile
65

7-
default_matrix: &default_matrix
6+
jobs_default: &jobs_default
7+
e:
8+
name: php/php
9+
php-version: << matrix.php-version >>
810
matrix:
911
parameters:
10-
php-version: [ "8.0", "8.1", "8.2" ]
12+
php-version: [ "8.1", "8.2" ]
13+
1114

1215
workflows:
1316
version: 2
1417
full:
1518
jobs:
1619
- php/phpunit-tests:
17-
<<: *default_matrix
20+
<<: *jobs_default
21+
minimum_coverage: 10
1822
- php/static-analysis:
19-
<<: *default_matrix
23+
<<: *jobs_default
2024
generate_ide_helper: false

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/.phpunit.result.cache
21
/vendor/
32
/.idea
43
composer.lock
4+
*.cache

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
"minimum-stability": "dev",
2323
"prefer-stable": true,
2424
"require": {
25-
"php": "^7.3 || ^8.0",
25+
"php": "^8.1",
2626
"bigcommerce/injector": "^3.0",
2727
"phpspec/prophecy-phpunit": "^2.0",
28-
"phpunit/phpunit": " ^9.0"
28+
"phpunit/phpunit": " ^10.0"
2929
},
3030
"require-dev": {
3131
"phpstan/phpstan": "^1.10"

phpunit.xml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
4-
backupGlobals="false"
5-
colors="true"
6-
bootstrap="vendor/autoload.php"
7-
convertWarningsToExceptions="true"
8-
failOnWarning="true"
9-
failOnRisky="true"
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
backupGlobals="false"
5+
colors="true"
6+
bootstrap="vendor/autoload.php"
7+
failOnWarning="true"
8+
failOnRisky="true"
9+
cacheDirectory=".phpunit.cache"
1010
>
11-
<coverage>
12-
<include>
13-
<directory suffix=".php">src</directory>
14-
</include>
15-
</coverage>
1611
<testsuites>
1712
<testsuite name="MockInjector Test Suite">
1813
<directory>./tests</directory>
@@ -23,4 +18,9 @@
2318
<group>dummy</group>
2419
</exclude>
2520
</groups>
21+
<source>
22+
<include>
23+
<directory>src</directory>
24+
</include>
25+
</source>
2626
</phpunit>

tests/AutoMockingTestTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types = 1);
34

45
namespace Tests;
@@ -8,21 +9,21 @@
89

910
class AutoMockingTestTest extends TestCase
1011
{
11-
public function testTestShouldNotBeRiskyWhenItHasProphecyExpectations()
12+
public function testTestShouldNotBeRiskyWhenItHasProphecyExpectations(): void
1213
{
1314
$riskyTest = new DummyTest('testWithProphecyExpectations');
1415

1516
$riskyTest->runBare();
1617

17-
$this->assertSame(1, $riskyTest->getNumAssertions());
18+
$this->assertSame(1, $riskyTest->numberOfAssertionsPerformed());
1819
}
1920

20-
public function testTestShouldBeRiskyWhenItHasNoAssertions()
21+
public function testTestShouldBeRiskyWhenItHasNoAssertions(): void
2122
{
2223
$riskyTest = new DummyTest('testWithoutAssertions');
2324

2425
$riskyTest->runBare();
2526

26-
$this->assertSame(0, $riskyTest->getNumAssertions());
27+
$this->assertSame(0, $riskyTest->numberOfAssertionsPerformed());
2728
}
2829
}

tests/Dummy/DummyDependency.php

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,20 @@
11
<?php
2+
23
namespace Tests\Dummy;
34

45
/**
56
* Dummy class that the Injector can easily create as a dependency
67
*/
78
class DummyDependency
89
{
9-
/**
10-
* @var bool
11-
*/
12-
private $enabled;
13-
14-
/**
15-
* @var DummySubDependency
16-
*/
17-
private $dependency;
18-
19-
/**
20-
* DummyDependency constructor.
21-
* @param DummySubDependency $dependency
22-
* @param bool $enabled
23-
*/
24-
public function __construct(DummySubDependency $dependency, $enabled = true)
25-
{
26-
$this->enabled = $enabled;
27-
$this->dependency = $dependency;
28-
}
2910

30-
/**
31-
* @return boolean
32-
*/
33-
public function isEnabled()
11+
public function __construct(
12+
private readonly DummySubDependency $dependency
13+
)
3414
{
35-
return $this->enabled;
3615
}
3716

38-
/**
39-
* @return DummySubDependency
40-
*/
41-
public function getDependency()
17+
public function getDependency(): DummySubDependency
4218
{
4319
return $this->dependency;
4420
}

tests/Dummy/DummyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DummyTest extends AutoMockingTest
1515
* This is a dummy test which is called by AutoMockInjectorTestTest. It has one expectation configured using
1616
* Prophecy (see `->shouldBeCalled()`), therefore there is 1 assertion and the test shouldn't be marked as Risky.
1717
*/
18-
public function testWithProphecyExpectations()
18+
public function testWithProphecyExpectations() : void
1919
{
2020
/** @var DummyDependency $dummyDependency */
2121
$dummyDependency = $this->createWithMocks(DummyDependency::class);
@@ -30,7 +30,7 @@ public function testWithProphecyExpectations()
3030
/**
3131
* This is a dummy test which doesn't have any assertions, therefore is risky.
3232
*/
33-
public function testWithoutAssertions()
33+
public function testWithoutAssertions() : void
3434
{
3535
}
3636
}

tests/MockInjectorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function setUp(): void
3030
/**
3131
* @covers ::create
3232
*/
33-
public function testCreate()
33+
public function testCreate() : void
3434
{
3535
$this->mockInjector->create("abc123", [1 => "hello"])->willReturn("cat")->shouldBeCalledTimes(1);
3636
$i = new MockInjector($this->mockContainer->reveal(), $this->mockInjector->reveal());
@@ -40,7 +40,7 @@ public function testCreate()
4040
/**
4141
* @covers ::invoke
4242
*/
43-
public function testInvoke()
43+
public function testInvoke() : void
4444
{
4545
$obj = new \stdClass();
4646
$this->mockInjector->invoke($obj, "method1", [1 => "hello"])->willReturn("fish")->shouldBeCalledTimes(1);
@@ -51,7 +51,7 @@ public function testInvoke()
5151
/**
5252
* @covers ::checkPredictions
5353
*/
54-
public function testCheckPredictions()
54+
public function testCheckPredictions() : void
5555
{
5656
$this->mockContainer->checkPredictions()->shouldBeCalledTimes(1);
5757
$i = new MockInjector($this->mockContainer->reveal(), $this->mockInjector->reveal());
@@ -61,7 +61,7 @@ public function testCheckPredictions()
6161
/**
6262
* @covers ::getAllMocks
6363
*/
64-
public function testGetAllMocks()
64+
public function testGetAllMocks() : void
6565
{
6666
$this->mockContainer->getAllMocks()->willReturn([1, 2, 6])->shouldBeCalledTimes(1);
6767
$i = new MockInjector($this->mockContainer->reveal(), $this->mockInjector->reveal());
@@ -71,7 +71,7 @@ public function testGetAllMocks()
7171
/**
7272
* @covers ::getMock
7373
*/
74-
public function testGetMock()
74+
public function testGetMock() : void
7575
{
7676
$dummy = new \stdClass();
7777
$this->mockContainer->getMock("blah")->willReturn($dummy)->shouldBeCalledTimes(1);
@@ -84,7 +84,7 @@ public function testGetMock()
8484
* and will instantiate an object with an auto-mocked dependency.
8585
* @covers ::__construct
8686
*/
87-
public function testWithoutDependencies()
87+
public function testWithoutDependencies() : void
8888
{
8989
$i = new MockInjector();
9090
/** @var DummyDependency $obj */

0 commit comments

Comments
 (0)