Skip to content

Commit 8796392

Browse files
committed
modernization. phpunit 9, package upgrades, newer php syntax and features
1 parent 59f9d59 commit 8796392

File tree

6 files changed

+33
-50
lines changed

6 files changed

+33
-50
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
composer.lock
22
composer.phar
3-
/vendor/
3+
/vendor/
4+
.phpunit.result.cache

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,25 @@ and create a new one in your computer.
3131

3232
php composer.phar create-project kata/php bowling-kata dev-master
3333

34-
Then add your classes to 'src/Kata' and your test cases to
35-
'src/Kata/Tests' and run 'php bin/phpunit' to run your tests.
34+
Then add your classes to `src/Kata` and your test cases to
35+
`src/Kata/Tests` and run `php bin/phpunit` to run your tests.
3636

3737
php bin/phpunit
3838

3939
TestCase examples
4040
=================
4141

42-
If you run 'php bin/phpunit' you will see the following output.
42+
If you run `php bin/phpunit` you will see the following output.
4343

44-
PHPUnit 3.8-gc4f2bcd by Sebastian Bergmann.
44+
PHPUnit 9.5.20
4545

46-
Configuration read from /Users/carlosbuenosvinos/Documents/Web/bowling/phpunit.xml
46+
... 3 / 3 (100%)
4747

48-
...
48+
Time: 00:00.003, Memory: 6.00 MB
4949

50-
Time: 91 ms, Memory: 1.75Mb
5150
OK (3 tests, 3 assertions)
5251

5352
That's because you will find one class and its TestCase in the project
5453
in order to help you. You can delete them.
5554

56-
Adder is a class that adds two numbers and AdderTest tests that.
55+
`Adder` is a class that adds two numbers and `AdderTest` tests that.

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "kata/php",
33
"description": "PHP Kata skeleton",
4-
"keywords": ["kata","TDD"],
4+
"keywords": ["kata", "TDD"],
55
"homepage": "https://github.com/carlosbuenosvinos/php-kata",
66
"type": "library",
77
"require-dev": {
8-
"phpunit/phpunit": "5.5.*@dev",
9-
"mockery/mockery": "dev-master@dev",
10-
"phpspec/phpspec": "3.0.*@dev"
8+
"phpunit/phpunit": "^9.5",
9+
"mockery/mockery": "^1.5",
10+
"phpspec/phpspec": "^7.0"
1111
},
1212
"license": "MIT",
1313
"authors": [
@@ -18,7 +18,8 @@
1818
],
1919
"autoload": {
2020
"psr-4": {
21-
"Kata\\": "src/"
21+
"Kata\\": "src/",
22+
"Kata\\Tests\\": "tests/"
2223
}
2324
},
2425
"config": {

phpunit.xml

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
syntaxCheck="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
124
bootstrap="vendor/autoload.php"
13-
>
5+
colors="true">
146
<php>
157
<ini name="intl.default_locale" value="en"/>
168
<ini name="intl.error_level" value="0"/>
@@ -23,9 +15,9 @@
2315
</testsuite>
2416
</testsuites>
2517

26-
<filter>
27-
<whitelist>
28-
<directory>./src/</directory>
29-
</whitelist>
30-
</filter>
31-
</phpunit>
18+
<coverage processUncoveredFiles="true">
19+
<include>
20+
<directory suffix=".php">./src</directory>
21+
</include>
22+
</coverage>
23+
</phpunit>

src/Adder.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
<?php
2+
23
namespace Kata;
34

4-
/**
5-
* Class Adder
6-
* @package Kata
7-
*/
85
class Adder
96
{
10-
/**
11-
* @param int $first
12-
* @param int $second
13-
* @return int
14-
*/
15-
public function add($first, $second)
7+
public function add(?int $first, ?int $second): int
168
{
179
return (int) $first + (int) $second;
1810
}
19-
}
11+
}

tests/AdderTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
<?php
2+
23
namespace Kata\Tests;
34

45
use Kata\Adder;
6+
use PHPUnit\Framework\TestCase;
57

6-
class AdderTest extends \PHPUnit_Framework_TestCase
8+
class AdderTest extends TestCase
79
{
810
/**
9-
* @test
1011
* @dataProvider validSumsProvider
11-
* @param int $a
12-
* @param int $b
13-
* @param $expectedResult
1412
*/
15-
public function validSums($a, $b, $expectedResult)
13+
public function testValidSums(?int $a, ?int $b, int $expectedResult): void
1614
{
1715
$this->assertEquals(
1816
$expectedResult,
1917
(new Adder())->add($a, $b)
2018
);
2119
}
2220

23-
public function validSumsProvider()
21+
public function validSumsProvider(): array
2422
{
2523
return [
2624
[null, null, 0],
2725
[0, 0, 0],
2826
[1, 1, 2]
2927
];
3028
}
31-
}
29+
}

0 commit comments

Comments
 (0)