Skip to content

Commit

Permalink
Merge pull request #82 from rn0/fixed_tests
Browse files Browse the repository at this point in the history
CS for rest of tests
  • Loading branch information
chives authored Jun 15, 2018
2 parents 0794c22 + 9a357ee commit ad0a1cb
Show file tree
Hide file tree
Showing 24 changed files with 434 additions and 641 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"fsi/data-indexer" : "0.9.*"
},
"require-dev": {
"doctrine/orm": "^2.5",
"doctrine/orm": "^2.6",
"doctrine/common": "^2.4",
"doctrine/collections": "^1.1",
"phpunit/phpunit": "^5.7"
"phpunit/phpunit": "^7.2"
},
"autoload": {
"psr-4": {
Expand Down
13 changes: 2 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.7/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.2/phpunit.xsd"
colors="true">
<testsuites>
<testsuite name="FSi Datasource Component Test Suite">
<directory>tests</directory>
Expand Down
75 changes: 37 additions & 38 deletions tests/DataSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
use FSi\Component\DataSource\Field\FieldTypeInterface;
use FSi\Component\DataSource\Tests\Fixtures\TestResult;
use FSi\Component\DataSource\Tests\Fixtures\DataSourceExtension;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Tests for DataSource.
*/
class DataSourceTest extends \PHPUnit_Framework_TestCase
class DataSourceTest extends TestCase
{
/**
* Basic creation of DataSource.
* @doesNotPerformAssertions
*/
public function testDataSourceCreate()
{
Expand All @@ -54,7 +53,7 @@ public function testDataSourceName()
*/
public function testDataSourceCreateException2()
{
$this->setExpectedException(DataSourceException::class);
$this->expectException(DataSourceException::class);
new DataSource($this->createDriverMock(), 'wrong-name');
}

Expand All @@ -63,7 +62,7 @@ public function testDataSourceCreateException2()
*/
public function testDataSourceCreateException3()
{
$this->setExpectedException(DataSourceException::class);
$this->expectException(DataSourceException::class);
new DataSource($this->createDriverMock(), '');
}

Expand All @@ -79,18 +78,18 @@ public function testDataSourceExtensionsLoad()
$extension1
->expects($this->once())
->method('loadDriverExtensions')
->will($this->returnValue([]))
->willReturn([])
;
$extension2
->expects($this->once())
->method('loadDriverExtensions')
->will($this->returnValue([]))
->willReturn([])
;

$datasource->addExtension($extension1);
$datasource->addExtension($extension2);

$this->assertEquals(count($datasource->getExtensions()), 2);
$this->assertCount(2, $datasource->getExtensions());
}

/**
Expand All @@ -99,7 +98,7 @@ public function testDataSourceExtensionsLoad()
public function testWrongFieldAddException1()
{
$datasource = new DataSource($this->createDriverMock());
$this->setExpectedException(DataSourceException::class);
$this->expectException(DataSourceException::class);
$datasource->addField('field', 'type');
}

Expand All @@ -109,7 +108,7 @@ public function testWrongFieldAddException1()
public function testWrongFieldAddException2()
{
$datasource = new DataSource($this->createDriverMock());
$this->setExpectedException(DataSourceException::class);
$this->expectException(DataSourceException::class);
$datasource->addField('field', '', 'type');
}

Expand All @@ -119,7 +118,7 @@ public function testWrongFieldAddException2()
public function testWrongFieldAddException3()
{
$datasource = new DataSource($this->createDriverMock());
$this->setExpectedException(DataSourceException::class);
$this->expectException(DataSourceException::class);
$datasource->addField('field');
}

Expand All @@ -129,14 +128,14 @@ public function testWrongFieldAddException3()
public function testWrongFieldAddException4()
{
$datasource = new DataSource($this->createDriverMock());
$this->setExpectedException(DataSourceException::class);
$this->expectException(DataSourceException::class);

$field = $this->createMock(FieldTypeInterface::class);

$field
->expects($this->once())
->method('getName')
->will($this->returnValue(null))
->willReturn(null)
;

$datasource->addField($field);
Expand Down Expand Up @@ -172,38 +171,38 @@ public function testFieldManipulation()
$field
->expects($this->once())
->method('getName')
->will($this->returnValue('name'))
->willReturn('name')
;

$driver
->expects($this->once())
->method('getFieldType')
->with('text')
->will($this->returnValue($field))
->willReturn($field)
;

$datasource->addField('name1', 'text', 'comp1');

$this->assertEquals(count($datasource->getFields()), 1);
$this->assertCount(1, $datasource->getFields());
$this->assertTrue($datasource->hasField('name1'));
$this->assertFalse($datasource->hasField('wrong'));

$datasource->clearFields();
$this->assertEquals(count($datasource->getFields()), 0);
$this->assertCount(0, $datasource->getFields());

$datasource->addField($field);
$this->assertEquals(count($datasource->getFields()), 1);
$this->assertCount(1, $datasource->getFields());
$this->assertTrue($datasource->hasField('name'));
$this->assertFalse($datasource->hasField('name1'));
$this->assertFalse($datasource->hasField('name2'));

$this->assertEquals($field, $datasource->getField('name'));

$this->assertTrue($datasource->removeField('name'));
$this->assertEquals(count($datasource->getFields()), 0);
$this->assertCount(0, $datasource->getFields());
$this->assertFalse($datasource->removeField('name'));

$this->setExpectedException(DataSourceException::class);
$this->expectException(DataSourceException::class);
$datasource->getField('wrong');
}

Expand All @@ -214,7 +213,7 @@ public function testBindParametersException()
{
$datasource = new DataSource($this->createDriverMock());
$datasource->bindParameters([]);
$this->setExpectedException(DataSourceException::class);
$this->expectException(DataSourceException::class);
$datasource->bindParameters('nonarray');
}

Expand Down Expand Up @@ -245,7 +244,7 @@ public function testBindAndGetResult()
$field
->expects($this->any())
->method('getName')
->will($this->returnValue('field'))
->willReturn('field')
;

$field
Expand All @@ -257,7 +256,7 @@ public function testBindAndGetResult()
->expects($this->once())
->method('getResult')
->with(['field' => $field])
->will($this->returnValue($testResult))
->willReturn($testResult)
;

$datasource->addField($field);
Expand All @@ -278,9 +277,9 @@ public function testWrongResult1()
$driver
->expects($this->once())
->method('getResult')
->will($this->returnValue('scalar'))
->willReturn('scalar')
;
$this->setExpectedException(DataSourceException::class);
$this->expectException(DataSourceException::class);
$datasource->getResult();
}

Expand All @@ -295,9 +294,9 @@ public function testWrongResult2()
$driver
->expects($this->once())
->method('getResult')
->will($this->returnValue(new \stdClass()))
->willReturn(new \stdClass())
;
$this->setExpectedException(DataSourceException::class);
$this->expectException(DataSourceException::class);
$datasource->getResult();
}

Expand Down Expand Up @@ -331,7 +330,7 @@ public function testGetParameters()
$field
->expects($this->atLeastOnce())
->method('getName')
->will($this->returnValue('key'))
->willReturn('key')
;

$field
Expand All @@ -343,7 +342,7 @@ public function testGetParameters()
$field2
->expects($this->atLeastOnce())
->method('getName')
->will($this->returnValue('key2'))
->willReturn('key2')
;

$field2
Expand All @@ -366,12 +365,12 @@ public function testViewCreation()
$driver
->expects($this->once())
->method('getResult')
->will($this->returnValue(new ArrayCollection()))
->willReturn(new ArrayCollection())
;

$datasource = new DataSource($driver);
$view = $datasource->createView();
$this->assertTrue($view instanceof DataSourceViewInterface);
$this->assertInstanceOf(DataSourceViewInterface::class, $view);
}

/**
Expand Down Expand Up @@ -423,19 +422,19 @@ public function testDriverExtensionLoading()
$extension
->expects($this->once())
->method('loadDriverExtensions')
->will($this->returnValue([$driverExtension]))
->willReturn([$driverExtension])
;

$driverExtension
->expects($this->once())
->method('getExtendedDriverTypes')
->will($this->returnValue(['fake']))
->willReturn(['fake'])
;

$driver
->expects($this->once())
->method('getType')
->will($this->returnValue('fake'))
->willReturn('fake')
;

$driver
Expand All @@ -462,7 +461,7 @@ public function testExtensionsCalls()
$driver
->expects($this->any())
->method('getResult')
->will($this->returnValue($testResult))
->willReturn($testResult)
;

$datasource->bindParameters([]);
Expand All @@ -482,7 +481,7 @@ public function testExtensionsCalls()
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
* @return DriverInterface|MockObject
*/
private function createDriverMock()
{
Expand Down
Loading

0 comments on commit ad0a1cb

Please sign in to comment.