Skip to content

Test enhancement #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ before_script:
script:
- vendor/bin/phpunit --configuration phpunit.xml.dist --colors

jobs:
matrix:
allow_failures:
- php: nightly

jobs:
include:
- stage: Coding standards
script:
Expand Down
5 changes: 5 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
14 changes: 7 additions & 7 deletions tests/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace PHPFluent\ArrayStorage;

use PHPFluent\ArrayStorage\Filter\Filter;
use PHPUnit\Framework\TestCase;
use function count;
use function iterator_to_array;

/**
Expand All @@ -19,7 +19,7 @@ public function testShouldUseFactoryToCreateRecords(): void
$record = new Record($data);

$factory = $this
->getMockBuilder('PHPFluent\\ArrayStorage\\Factory')
->getMockBuilder(Factory::class)
->disableOriginalConstructor()
->getMock();

Expand All @@ -37,11 +37,11 @@ public function testShouldUseFactoryToCreateRecords(): void
public function testShouldUseFactoryToCreateCriteria(): void
{
$factory = $this
->getMockBuilder('PHPFluent\\ArrayStorage\\Factory')
->getMockBuilder(Factory::class)
->disableOriginalConstructor()
->getMock();

$filters = ['foo' => $this->createMock('PHPFluent\\ArrayStorage\\Filter\\Filter')];
$filters = ['foo' => $this->createMock(Filter::class)];

$criteria = new Criteria($factory);
$criteria->addFilter('foo', $filters['foo']);
Expand Down Expand Up @@ -90,15 +90,15 @@ public function testShouldIterateOverRecords(): void
$collection->insert(new Record());
$collection->insert(new Record());
$collection->insert(new Record());
$count = count(iterator_to_array($collection));
$count = iterator_to_array($collection);

$this->assertEquals(3, $count);
$this->assertCount(3, $count);
}

public function testShouldReturnAnInstanceOfCollectionWhenFindingRecords(): void
{
$factory = $this
->getMockBuilder('PHPFluent\\ArrayStorage\\Factory')
->getMockBuilder(Factory::class)
->disableOriginalConstructor()
->getMock();

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

namespace PHPFluent\ArrayStorage;

use PHPFluent\ArrayStorage\Filter\EqualTo;
use PHPFluent\ArrayStorage\Filter\Filter;
use PHPUnit\Framework\TestCase;
use UnexpectedValueException;
Expand Down Expand Up @@ -41,14 +42,14 @@ public function testShouldAddFilterUsingMethodOverload(): void
[$index, $filter] = $filters[0];

$this->assertEquals('foo', $index);
$this->assertInstanceOf('PHPFluent\\ArrayStorage\\Filter\\EqualTo', $filter);
$this->assertInstanceOf(EqualTo::class, $filter);
}

public function testShouldUseFactoryToCreateFilters(): void
{
$filter = $this->createMock('PHPFluent\\ArrayStorage\\Filter\\Filter');
$filter = $this->createMock(Filter::class);

$factory = $this->createMock('PHPFluent\\ArrayStorage\\Factory');
$factory = $this->createMock(Factory::class);
$factory
->expects($this->once())
->method('filter')
Expand Down
14 changes: 7 additions & 7 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public function testShouldCreateCollection(): void
{
$factory = new Factory();

$this->assertInstanceOf('PHPFluent\\ArrayStorage\\Collection', $factory->collection());
$this->assertInstanceOf(Collection::class, $factory->collection());
}

public function testShouldReturnInputIfInputIsAlreadyCollection(): void
{
$collection = $this
->getMockBuilder('PHPFluent\\ArrayStorage\\Collection')
->getMockBuilder(Collection::class)
->disableOriginalConstructor()
->getMock();

Expand All @@ -48,7 +48,7 @@ public function testShouldCreateNewRecord(): void
$factory = new Factory();
$record = $factory->record();

$this->assertInstanceOf(__NAMESPACE__.'\\Record', $record);
$this->assertInstanceOf(Record::class, $record);
}

public function testShouldCreateNewRecordFromArray(): void
Expand All @@ -57,7 +57,7 @@ public function testShouldCreateNewRecordFromArray(): void
$data = [];
$record = $factory->record($data);

$this->assertInstanceOf(__NAMESPACE__.'\\Record', $record);
$this->assertInstanceOf(Record::class, $record);
}

public function testShouldCreateNewRecordFromStdClass(): void
Expand All @@ -66,7 +66,7 @@ public function testShouldCreateNewRecordFromStdClass(): void
$data = new stdClass();
$record = $factory->record($data);

$this->assertInstanceOf(__NAMESPACE__.'\\Record', $record);
$this->assertInstanceOf(Record::class, $record);
}

public function testShouldReturnTheSameInstanceWhenDataIsAlreadyRecordInstance(): void
Expand All @@ -83,13 +83,13 @@ public function testShouldCreateCriteria(): void
$factory = new Factory();
$criteria = $factory->criteria();

$this->assertInstanceOf(__NAMESPACE__.'\\Criteria', $criteria);
$this->assertInstanceOf(Criteria::class, $criteria);
}

public function testShouldCreateCriteriaFromKeyValueArrayOfFilters(): void
{
$inputFilters = [
'foo' => $this->createMock(__NAMESPACE__.'\\Filter\\Filter'),
'foo' => $this->createMock(Filter::class),
];
$factory = new Factory();
$criteria = $factory->criteria($inputFilters);
Expand Down
5 changes: 1 addition & 4 deletions tests/RecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace PHPFluent\ArrayStorage;

use PHPUnit\Framework\TestCase;
use function count;
use function iterator_to_array;

/**
Expand Down Expand Up @@ -61,8 +60,6 @@ public function testShouldIterateOverRecord(): void
$record->id = 1;
$record->name = 'Henrique Moody';

$count = count(iterator_to_array($record));

$this->assertEquals(2, $count);
$this->assertCount(2, iterator_to_array($record));
}
}
9 changes: 3 additions & 6 deletions tests/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace PHPFluent\ArrayStorage;

use PHPUnit\Framework\TestCase;
use function count;
use function iterator_to_array;

/**
Expand All @@ -18,13 +17,13 @@ public function testShouldGetCollectionWhenPropertyDoesNoExists(): void
$storage = new Storage();
$collection = $storage->whatever;

$this->assertInstanceOf(__NAMESPACE__.'\\Collection', $collection);
$this->assertInstanceOf(Collection::class, $collection);
}

public function testShouldUseFactoryToCreateCollections(): void
{
$factory = $this
->getMockBuilder('PHPFluent\\ArrayStorage\\Factory')
->getMockBuilder(Factory::class)
->disableOriginalConstructor()
->getMock();
$factory
Expand All @@ -50,8 +49,6 @@ public function testShouldIterateOverCollections(): void
$storage->foo;
$storage->bar;

$count = count(iterator_to_array($storage));

$this->assertEquals(2, $count);
$this->assertCount(2, iterator_to_array($storage));
}
}