Skip to content

Commit

Permalink
Test enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k committed Jul 22, 2018
1 parent 3f9854c commit 57f51eb
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.0|^5.7.0"
"phpunit/phpunit": "^4.8.0|^5.7.0|^6.5"
},
"config": {
"optimize-autoloader": true,
Expand Down
5 changes: 3 additions & 2 deletions tests/UnderscoreArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Ahc\Underscore\Tests;

use Ahc\Underscore\Underscore as _;
use PHPUnit\Framework\TestCase;

class UnderscoreArrayTest extends \PHPUnit_Framework_TestCase
class UnderscoreArrayTest extends TestCase
{
public function test_first_last()
{
Expand Down Expand Up @@ -120,7 +121,7 @@ public function test_object()
$array = [[1, 2], 'a' => 3, 'b' => 'B'];

foreach (underscore($array)->object() as $index => $value) {
$this->assertTrue(is_object($value));
$this->assertInternalType('object', $value);
$this->assertSame($index, $value->index);
$this->assertSame($array[$index], $value->value);
}
Expand Down
7 changes: 4 additions & 3 deletions tests/UnderscoreBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Ahc\Underscore\Tests;

use Ahc\Underscore\Underscore as _;
use PHPUnit\Framework\TestCase;

class Stub
{
Expand All @@ -20,7 +21,7 @@ public function jsonSerialize()
}
}

class UnderscoreBaseTest extends \PHPUnit_Framework_TestCase
class UnderscoreBaseTest extends TestCase
{
public function test_asArray()
{
Expand All @@ -47,7 +48,7 @@ public function test_underscore()

public function test_now()
{
$this->assertTrue(is_float(_::_()->now()));
$this->assertInternalType('float', _::_()->now());
}

public function test_keys_values()
Expand Down Expand Up @@ -113,7 +114,7 @@ public function test_mixin()

$und = underscore([10, 20, 30]);

$this->assertTrue(is_callable([$und, 'double']));
$this->assertInternalType('callable', [$und, 'double']);
$this->assertSame([20, 40, 60], $und->double()->toArray());

$und->notMixedIn();
Expand Down
12 changes: 8 additions & 4 deletions tests/UnderscoreCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Ahc\Underscore\Tests;

class UnderscoreCollectionTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class UnderscoreCollectionTest extends TestCase
{
public function test_array_json_props()
{
Expand Down Expand Up @@ -33,7 +35,7 @@ public function test_array_json_props()
}

/**
* @expectedException \PHPUnit_Framework_Error_Notice
* @expectedException \PHPUnit\Framework\Error\Notice
* @expectedExceptionMessage Undefined offset: 5
*/
public function test_get()
Expand Down Expand Up @@ -310,7 +312,8 @@ public function test_sortBy()
$byA = $list->sortBy('a')->get();
$this->assertSame(
[2 => ['a' => 0, 'b' => 1], 0 => ['a' => 1, 'b' => 2], 1 => ['a' => 2, 'b' => 3]],
$byA, 'sort by a'
$byA,
'sort by a'
);

$byAB = $list->sortBy(function ($i) {
Expand All @@ -319,7 +322,8 @@ public function test_sortBy()

$this->assertSame(
[2 => ['a' => 0, 'b' => 1], 0 => ['a' => 1, 'b' => 2], 1 => ['a' => 2, 'b' => 3]],
$byAB, 'sort by a+b'
$byAB,
'sort by a+b'
);
}

Expand Down
16 changes: 12 additions & 4 deletions tests/UnderscoreFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Ahc\Underscore\Tests;

class UnderscoreFunctionTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

class UnderscoreFunctionTest extends TestCase
{
public function test_memoize()
{
Expand All @@ -27,10 +29,14 @@ public function test_memoize()

$buffer = ob_get_clean();

$this->assertSame(1, substr_count($buffer, 'sum 1 + 2'),
$this->assertSame(
1,
substr_count($buffer, 'sum 1 + 2'),
'Should be called only once, subsequent calls uses memo'
);
$this->assertSame(1, substr_count($buffer, 'sum 3 + 2'),
$this->assertSame(
1,
substr_count($buffer, 'sum 3 + 2'),
'Should be called only once, subsequent calls uses memo'
);
}
Expand Down Expand Up @@ -76,7 +82,9 @@ public function test_throttle()

$buffer = ob_get_clean();

$this->assertLessThanOrEqual(3, substr_count($buffer, 'throttle'),
$this->assertLessThanOrEqual(
3,
substr_count($buffer, 'throttle'),
'Should be called only once, subsequent calls uses memo'
);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/UnderscoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Ahc\Underscore\Tests;

use Ahc\Underscore\Underscore as _;
use PHPUnit\Framework\TestCase;

class UnderscoreTest extends \PHPUnit_Framework_TestCase
class UnderscoreTest extends TestCase
{
public function test_constant()
{
Expand Down
4 changes: 4 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

if (class_exists('\PHPUnit_Framework_Error_Notice')) {
class_alias('\PHPUnit_Framework_Error_Notice', '\PHPUnit\Framework\Error\Notice');
}

0 comments on commit 57f51eb

Please sign in to comment.