PHPAntwerp meetup 2017-12-20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// .atoum.php | |
// $script->addDefaultArguments( | |
// '--loop' | |
// ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require-dev": { | |
"atoum/reports-extension": "^3.0", | |
"atoum/telemetry-extension": "^1.0", | |
"atoum/atoum": "^3.2" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php vendor/bin/atoum -ncc -f tests/UnitS/Foo.php --methods *::testIdenticalVsEqual | |
php vendor/bin/atoum -ncc -f tests/UnitS/Foo.php --methods *::testAsserterTypes | |
php vendor/bin/atoum -ncc -f tests/UnitS/Foo.php --methods *::testPrecision | |
php vendor/bin/atoum -ncc -f tests/UnitS/Foo.php | |
php vendor/bin/atoum -f tests/UnitS/Foo.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// parent-directory/tests/UnitS/Foo.php | |
namespace Foo\Bar { | |
class Number { | |
public function __construct($number) { | |
$this->number = $number; | |
} | |
} | |
class Foo { | |
public function baz(float $bar) { | |
return 1.1 + $bar; | |
} | |
public function unwrap(Number $number) { | |
return $number->number; | |
} | |
public function withIf(bool $a, bool $b) { | |
if ($a) { | |
echo 'a'; | |
} elseif ($b) { | |
echo 'b'; | |
} | |
if ($a && $b) { | |
echo 'ab'; | |
} | |
} | |
} | |
} | |
namespace test\UnIts\Foo\Bar { | |
class Foo extends \atoum { | |
public function testIdenticalVsEqual() { | |
$this->newTestedInstance; | |
$number = new \Foo\Bar\Number(42); | |
$this | |
->assert('basic value demonstration') | |
->variable($this->testedInstance->unwrap($number)) | |
->isEqualTo($number->number) | |
->isIdenticalTo($number->number); | |
$this | |
->assert('basic value demonstration, with new instance') | |
->variable($this->testedInstance->unwrap(new \Foo\Bar\Number(42))) | |
->isEqualTo($number->number) | |
->isIdenticalTo($number->number); | |
$number = new \Foo\Bar\Number($number); | |
$this | |
->assert('object comparison, same instance') | |
->variable($this->testedInstance->unwrap($number)) | |
->isEqualTo($number->number) | |
->isIdenticalTo($number->number); | |
$this | |
->assert('object comparison, with new instances') | |
->variable($this->testedInstance->unwrap(new \Foo\Bar\Number(new \Foo\Bar\Number(42)))) | |
->isEqualTo($number->number) | |
//->isIdenticalTo($number->number, 'That\'s a different instance'); | |
->isNotIdenticalTo($number->number, 'That\'s a different instance'); | |
} | |
public function testAsserterTypes() { | |
$this->newTestedInstance; | |
$number = new \Foo\Bar\Number(42); | |
$this | |
->assert('using variable (generic)') | |
->variable($this->testedInstance->unwrap($number)) | |
->isEqualTo($number->number) | |
->isIdenticalTo($number->number); | |
// 2 assertions | |
$this | |
->assert('using a type') | |
->integer($this->testedInstance->unwrap($number)) | |
->isEqualTo($number->number) | |
->isIdenticalTo($number->number); | |
// 3 assertions | |
} | |
public function testPrecision() { | |
$this->newTestedInstance; | |
$this | |
->float($this->testedInstance->baz(40.9)) | |
->isNotIdenticalTo(42) | |
->isEqualTo(42) | |
->isNearlyEqualTo(41.8, 0.01); | |
} | |
public function testAB() { | |
$this->newTestedInstance; | |
$this->output(function(){$this->testedInstance->withIf(true, false);})->isEqualTo('a'); | |
//$this->output(function(){$this->testedInstance->withIf(true, true);})->isEqualTo('aab'); | |
//$this->output(function(){$this->testedInstance->withIf(false, true);})->isEqualTo('b'); | |
//$this->output(function(){$this->testedInstance->withIf(false, false);})->isEqualTo(''); | |
} | |
public function testMock() { | |
$m = new \mock\Countable(); | |
$this->calling($m)->count = 1; | |
$this->calling($m)->count[2]->throw = new \DomainException('You can\'t count me'); | |
$this->integer(count($m))->isEqualTo(1); | |
$this->exception(function() use($m) {$this->integer(count($m));})->isInstanceOf(\DomainException::class); | |
$this->integer(count($m))->isEqualTo(1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment