Skip to content

Commit e1f7def

Browse files
committed
Refactor tests and dependencies:
- Remove unused `NamedArgumentsTest`. - Replace outdated PHPUnit docblock annotations with attributes. - Use `createStub` instead of `createMock` where applicable. - Update to PHPUnit 12 schema in `phpunit.xml`. - Set workflow PHP version to 8.3. - Minor adjustments in `Container` and `bootstrap.php` for improved modern compatibility.
1 parent 4486690 commit e1f7def

14 files changed

Lines changed: 78 additions & 164 deletions

File tree

.github/workflows/check.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup PHP
1616
uses: shivammathur/setup-php@v2
1717
with:
18-
php-version: '8.2'
18+
php-version: '8.3'
1919

2020
- name: Validate composer.json and composer.lock
2121
run: composer validate
@@ -47,7 +47,7 @@ jobs:
4747
- name: Setup PHP
4848
uses: shivammathur/setup-php@v2
4949
with:
50-
php-version: '8.2'
50+
php-version: '8.3'
5151

5252
- name: Validate composer.json and composer.lock
5353
run: composer validate

phpunit.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?xml version="1.0"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnError="false" stopOnFailure="false" verbose="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage includeUncoveredFiles="true">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
bootstrap="tests/bootstrap.php"
4+
colors="true"
5+
stopOnError="false"
6+
stopOnFailure="false"
7+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.5/phpunit.xsd">
8+
<source>
49
<include>
510
<directory>src/</directory>
611
<directory>recipe/</directory>
@@ -9,16 +14,18 @@
914
<directory suffix=".php">vendor/</directory>
1015
<directory>bin/</directory>
1116
</exclude>
12-
</coverage>
17+
</source>
1318
<testsuites>
1419
<testsuite name="Src">
1520
<directory>tests/src/</directory>
1621
</testsuite>
1722
<testsuite name="Legacy">
1823
<directory>tests/legacy/</directory>
24+
<exclude>tests/legacy/AbstractTest.php</exclude>
1925
</testsuite>
2026
<testsuite name="Joy">
2127
<directory>tests/joy/</directory>
28+
<exclude>tests/joy/JoyTest.php</exclude>
2229
</testsuite>
2330
</testsuites>
2431
</phpunit>

src/Component/Pimple/Container.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function factory(callable $callable)
176176
throw new ExpectedInvokableException('Service definition is not a Closure or invokable object.');
177177
}
178178

179-
$this->factories->attach($callable);
179+
$this->factories->offsetSet($callable, null);
180180

181181
return $callable;
182182
}
@@ -198,7 +198,7 @@ public function protect(callable $callable)
198198
throw new ExpectedInvokableException('Callable is not a Closure or invokable object.');
199199
}
200200

201-
$this->protected->attach($callable);
201+
$this->protected->offsetSet($callable, null);
202202

203203
return $callable;
204204
}
@@ -270,8 +270,8 @@ public function extend(string $id, callable $callable)
270270
};
271271

272272
if (isset($this->factories[$factory])) {
273-
$this->factories->detach($factory);
274-
$this->factories->attach($extended);
273+
$this->factories->offsetUnset($factory);
274+
$this->factories->offsetSet($extended, null);
275275
}
276276

277277
return $this[$id] = $extended;

tests/bootstrap.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
// Init repository
3333
$repository = __REPOSITORY__;
3434

35-
`cd $repository && git init`;
36-
$branch = trim(`git rev-parse --abbrev-ref HEAD`);
37-
`cd $repository && git checkout -B $branch 2>&1`;
38-
`cd $repository && git add .`;
39-
`cd $repository && git config user.name 'Anton Medvedev'`;
40-
`cd $repository && git config user.email 'anton.medv@example.com'`;
41-
`cd $repository && git commit -m 'first commit'`;
35+
shell_exec("cd $repository && git init");
36+
$branch = trim(shell_exec('git rev-parse --abbrev-ref HEAD'));
37+
shell_exec("cd $repository && git checkout -B $branch 2>&1");
38+
shell_exec("cd $repository && git add .");
39+
shell_exec("cd $repository && git config user.name 'Anton Medvedev'");
40+
shell_exec("cd $repository && git config user.email 'anton.medv@example.com'");
41+
shell_exec("cd $repository && git commit -m 'first commit'");

tests/legacy/DeployTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Deployer;
99

10+
use PHPUnit\Framework\Attributes\Depends;
1011
use Symfony\Component\Console\Output\Output;
1112

1213
class DeployTest extends AbstractTest
@@ -76,9 +77,7 @@ public function testKeepReleases()
7677
}
7778
}
7879

79-
/**
80-
* @depends testKeepReleases
81-
*/
80+
#[Depends('testKeepReleases')]
8281
public function testRollback()
8382
{
8483
$this->dep(self::RECIPE, 'rollback');
@@ -106,9 +105,7 @@ public function testFail()
106105
}
107106
}
108107

109-
/**
110-
* @depends testFail
111-
*/
108+
#[Depends('testFail')]
112109
public function testCleanup()
113110
{
114111
$this->dep(self::RECIPE, 'deploy:cleanup');

tests/legacy/NamedArgumentsTest.php

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

tests/legacy/YamlTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testDeploy()
4646
self::assertFileExists($deployPath . '/shared/.env');
4747
self::assertFileExists($deployPath . '/current/config/test.yaml');
4848
self::assertFileExists($deployPath . '/shared/config/test.yaml');
49-
self::assertEquals(1, intval(`cd $deployPath && ls -1 releases | wc -l`));
49+
self::assertEquals(1, intval(shell_exec("cd $deployPath && ls -1 releases | wc -l")));
5050
}
5151
}
5252
}

tests/src/Collection/CollectionTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
use Deployer\Host\HostCollection;
1111
use Deployer\Task\TaskCollection;
12+
use PHPUnit\Framework\Attributes\DataProvider;
13+
use PHPUnit\Framework\Attributes\Depends;
1214
use PHPUnit\Framework\TestCase;
1315

1416
class CollectionTest extends TestCase
@@ -22,9 +24,7 @@ public static function collections()
2224
];
2325
}
2426

25-
/**
26-
* @dataProvider collections
27-
*/
27+
#[DataProvider('collections')]
2828
public function testCollection($collection)
2929
{
3030
$this->assertInstanceOf(Collection::class, $collection);
@@ -40,10 +40,8 @@ public function testCollection($collection)
4040
}));
4141
}
4242

43-
/**
44-
* @dataProvider collections
45-
* @depends testCollection
46-
*/
43+
#[DataProvider('collections')]
44+
#[Depends('testCollection')]
4745
public function testException($collection)
4846
{
4947
$this->expectException(\InvalidArgumentException::class);

0 commit comments

Comments
 (0)