Skip to content
This repository has been archived by the owner on May 15, 2021. It is now read-only.

Commit

Permalink
:octocat: phpunit 8
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Mar 6, 2019
1 parent 29b4a87 commit e8859c5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 76 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"source": "https://github.com/chillerlan/php-traits"
},
"require": {
"php": ">=7.2.0",
"php": "^7.2",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.3"
"phpunit/phpunit": "^8.0"
},
"autoload": {
"psr-4": {
Expand Down
52 changes: 23 additions & 29 deletions tests/ArrayTrait/ByteArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace chillerlan\TraitTest;

use chillerlan\Traits\ArrayHelpers\ByteArrayDispenser;
use chillerlan\Traits\TraitException;
use PHPUnit\Framework\TestCase;

class ByteArrayTest extends TestCase{
Expand All @@ -22,7 +23,7 @@ class ByteArrayTest extends TestCase{
*/
protected $arrayDispenser;

protected function setUp(){
protected function setUp():void{
$this->arrayDispenser = new ByteArrayDispenser;
}

Expand Down Expand Up @@ -76,59 +77,52 @@ public function testGuessFrom($from){
$this->assertSame('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f', $this->arrayDispenser->guessFrom($from)->toHex());
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage invalid input
*/
public function testGuessFromInvalidData(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('invalid input');

$this->arrayDispenser->guessFrom(new \stdClass);
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage invalid size
*/
public function testInvalidIntException(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('invalid size');

$this->arrayDispenser->fromIntSize(-1);
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage invalid length
*/
public function testInvalidRangeException(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('invalid length');

$this->arrayDispenser->fromArrayFill(-1, 1);
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage invalid hex string
*/
public function testInvalidHexException(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('invalid hex string');

$this->arrayDispenser->fromHex('foo');
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage invalid JSON array
*/
public function testInvalidJSONException(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('invalid JSON array');

$this->arrayDispenser->fromJSON('{}');
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage invalid base64 string
*/
public function testInvalidBase64Exception(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('invalid base64 string');

$this->arrayDispenser->fromBase64('\\');
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage invalid binary string
*/
public function testInvalidBinException(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('invalid binary string');

$this->arrayDispenser->fromBin('2');
}

Expand Down
50 changes: 22 additions & 28 deletions tests/ClassLoader/ClassLoaderTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace chillerlan\TraitTest\ClassLoader;

use chillerlan\Traits\ClassLoader;
use chillerlan\Traits\TraitException;
use PHPUnit\Framework\TestCase;

class ClassLoaderTraitTest extends TestCase{
Expand All @@ -37,59 +38,52 @@ public function testLoadClass3(){
$this->assertSame('whatever', $obj->bar());
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage \whatever\foo does not exist
*/
public function testLoadClassExceptionA1(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('\whatever\foo does not exist');

$this->loadClass('\\whatever\\foo', tInterface::class);
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage \whatever\bar does not exist
*/
public function testLoadClassExceptionA2(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('\whatever\bar does not exist');

$this->loadClass(tClass::class, '\\whatever\\bar');
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage cannot be an instance of trait
*/
public function testLoadClassExceptionB(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('cannot be an instance of trait');

$this->loadClass(tClass::class, tTrait::class);
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage cannot instance abstract class
*/
public function testLoadClassExceptionC(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('cannot instance abstract class');

$this->loadClass(tAbstract::class, tInterface::class);
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage cannot instance trait
*/
public function testLoadClassExceptionD(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('cannot instance trait');

$this->loadClass(tTrait::class, tInterface::class);
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage does not implement
*/
public function testLoadClassExceptionE1(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('does not implement');

$this->loadClass(tClass::class, tInterface2::class);
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage does not inherit
*/
public function testLoadClassExceptionE2(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('does not inherit');

$this->loadClass(tClass::class, \stdClass::class);
}

Expand Down
24 changes: 11 additions & 13 deletions tests/Enumerable/EnumerableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace chillerlan\TraitTest\Enumerable;

use chillerlan\Traits\TraitException;
use PHPUnit\Framework\TestCase;

class EnumerableTest extends TestCase{
Expand All @@ -23,7 +24,7 @@ class EnumerableTest extends TestCase{
*/
protected $enumerable;

protected function setUp(){
protected function setUp():void{
$this->enumerable = new EnumerableContainer($this->array);
}

Expand Down Expand Up @@ -112,27 +113,24 @@ public function testReject(){
$this->assertSame([1, 3, 5], $arr);
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage invalid callback
*/
public function testMapInvalidCallback(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('invalid callback');

(new EnumerableContainer([]))->__map('foo');
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage invalid callback
*/
public function testFindAllInvalidCallback(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('invalid callback');

(new EnumerableContainer([]))->__findAll('foo');
}

/**
* @expectedException \chillerlan\Traits\TraitException
* @expectedExceptionMessage invalid callback
*/
public function testRejectInvalidCallback(){
$this->expectException(TraitException::class);
$this->expectExceptionMessage('invalid callback');

(new EnumerableContainer([]))->__reject('foo');
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Interfaces/ArrayAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace chillerlan\TraitTest\Interfaces;

use OutOfBoundsException;
use PHPUnit\Framework\TestCase;

class ArrayAccessTest extends TestCase{
Expand Down Expand Up @@ -42,11 +43,10 @@ public function testInstance(){
$this->assertCount(0, $x);
}

/**
* @expectedException \OutOfBoundsException
* @expectedExceptionMessage invalid seek position: 69
*/
public function testSeekInvalidPos(){
$this->expectException(OutOfBoundsException::class);
$this->expectExceptionMessage('invalid seek position: 69');

$x = new TestArrayAccessContainer;
$x->seek(69);
}
Expand Down

0 comments on commit e8859c5

Please sign in to comment.