Skip to content

Commit

Permalink
modernization. phpunit 9, package upgrades, newer php syntax and feat…
Browse files Browse the repository at this point in the history
…ures
  • Loading branch information
tanerkay committed May 18, 2022
1 parent 59f9d59 commit 8796392
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
composer.phar
/vendor/
/vendor/
.phpunit.result.cache
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,25 @@ and create a new one in your computer.

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

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

php bin/phpunit

TestCase examples
=================

If you run 'php bin/phpunit' you will see the following output.
If you run `php bin/phpunit` you will see the following output.

PHPUnit 3.8-gc4f2bcd by Sebastian Bergmann.
PHPUnit 9.5.20

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

...
Time: 00:00.003, Memory: 6.00 MB

Time: 91 ms, Memory: 1.75Mb
OK (3 tests, 3 assertions)

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

Adder is a class that adds two numbers and AdderTest tests that.
`Adder` is a class that adds two numbers and `AdderTest` tests that.
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "kata/php",
"description": "PHP Kata skeleton",
"keywords": ["kata","TDD"],
"keywords": ["kata", "TDD"],
"homepage": "https://github.com/carlosbuenosvinos/php-kata",
"type": "library",
"require-dev": {
"phpunit/phpunit": "5.5.*@dev",
"mockery/mockery": "dev-master@dev",
"phpspec/phpspec": "3.0.*@dev"
"phpunit/phpunit": "^9.5",
"mockery/mockery": "^1.5",
"phpspec/phpspec": "^7.0"
},
"license": "MIT",
"authors": [
Expand All @@ -18,7 +18,8 @@
],
"autoload": {
"psr-4": {
"Kata\\": "src/"
"Kata\\": "src/",
"Kata\\Tests\\": "tests/"
}
},
"config": {
Expand Down
26 changes: 9 additions & 17 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
>
colors="true">
<php>
<ini name="intl.default_locale" value="en"/>
<ini name="intl.error_level" value="0"/>
Expand All @@ -23,9 +15,9 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</phpunit>
14 changes: 3 additions & 11 deletions src/Adder.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<?php

namespace Kata;

/**
* Class Adder
* @package Kata
*/
class Adder
{
/**
* @param int $first
* @param int $second
* @return int
*/
public function add($first, $second)
public function add(?int $first, ?int $second): int
{
return (int) $first + (int) $second;
}
}
}
14 changes: 6 additions & 8 deletions tests/AdderTest.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
<?php

namespace Kata\Tests;

use Kata\Adder;
use PHPUnit\Framework\TestCase;

class AdderTest extends \PHPUnit_Framework_TestCase
class AdderTest extends TestCase
{
/**
* @test
* @dataProvider validSumsProvider
* @param int $a
* @param int $b
* @param $expectedResult
*/
public function validSums($a, $b, $expectedResult)
public function testValidSums(?int $a, ?int $b, int $expectedResult): void
{
$this->assertEquals(
$expectedResult,
(new Adder())->add($a, $b)
);
}

public function validSumsProvider()
public function validSumsProvider(): array
{
return [
[null, null, 0],
[0, 0, 0],
[1, 1, 2]
];
}
}
}

0 comments on commit 8796392

Please sign in to comment.