Skip to content

Improve assertions #189

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

Merged
merged 1 commit into from
Feb 28, 2018
Merged
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
8 changes: 4 additions & 4 deletions tests/NodeTypeDiscovery/NodeDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,24 @@ public function getRequiredPrimaryTypeNames()
{
$names = $this->content->getRequiredPrimaryTypeNames();
$this->assertInternalType('array', $names);
$this->assertTrue(1, count($names));
$this->assertCount(1, $names);
$this->assertEquals('nt:base', $names[0]);

$names = $this->hierarchyNodeDef->getRequiredPrimaryTypeNames();
$this->assertInternalType('array', $names);
$this->assertTrue(1, count($names));
$this->assertCount(1, $names);
$this->assertEquals('nt:hierarchyNode', $names[0]);
}
public function getRequiredPrimaryTypes()
{
$types = $this->content->getRequiredPrimaryTypeNames();
$this->assertInternalType('array', $types);
$this->assertTrue(1, count($types));
$this->assertCount(1, $types);
$this->assertEquals(self::$base, $types[0]);

$types = $this->hierarchyNodeDef->getRequiredPrimaryTypeNames();
$this->assertInternalType('array', $types);
$this->assertTrue(1, count($types));
$this->assertCount(1, $types);
$this->assertEquals(self::$hierarchyNodeType, $types[0]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Observation/ObservationManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function assertFilterOnPathDeep(ObservationManagerInterface $observati
$journal->next();

// Notice the assertion is slightly different from the one in testFilterOnPathNoDeep
$this->assertTrue(substr($event->getPath(), 0, strlen($this->nodePath.'/child')) === $this->nodePath.'/child');
$this->assertSame($this->nodePath.'/child', substr($event->getPath(), 0, strlen($this->nodePath.'/child')));
}
}

Expand Down
12 changes: 6 additions & 6 deletions tests/PhpcrUtils/CndParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ public function testNoStopAtEofError()
{
$res = $this->cndParser->parseFile(__DIR__.'/resources/cnd/no-stop-at-eof.cnd');

$this->assertTrue(isset($res['namespaces']));
$this->assertArrayHasKey('namespaces', $res);
$this->assertEquals(['phpcr' => 'http://www.doctrine-project.org/projects/phpcr_odm'], $res['namespaces']);

$this->assertTrue(isset($res['nodeTypes']));
$this->assertArrayHasKey('nodeTypes', $res);
}

public function testBigFile()
Expand All @@ -169,10 +169,10 @@ public function testBigFile()
$res = $this->cndParser->parseFile(__DIR__.'/resources/cnd/jackrabbit_nodetypes.cnd');

// some random sanity checks
$this->assertTrue(isset($res['nodeTypes']));
$this->assertArrayHasKey('nodeTypes', $res);

$def = $res['nodeTypes'];
$this->assertTrue(isset($def['nt:file']));
$this->assertArrayHasKey('nt:file', $def);
/** @var $parsed NodeTypeDefinitionInterface */
$parsed = $def['nt:file'];
$this->assertEquals('nt:file', $parsed->getName());
Expand All @@ -190,10 +190,10 @@ public function testBigFile()
*/
protected function assertExampleCnd($res)
{
$this->assertTrue(isset($res['namespaces']));
$this->assertArrayHasKey('namespaces', $res);
$this->assertEquals(['ns' => 'http://namespace.com/ns'], $res['namespaces']);

$this->assertTrue(isset($res['nodeTypes']));
$this->assertArrayHasKey('nodeTypes', $res);
// get first node type
reset($res['nodeTypes']);
/** @var $def NodeTypeDefinitionInterface */
Expand Down
2 changes: 1 addition & 1 deletion tests/Query/NodeViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ public function testCountable()
$nodes[] = $node;
}

$this->assertEquals(count($nodes), $this->nodeIterator->count());
$this->assertCount($this->nodeIterator->count(), $nodes);
}
}
2 changes: 1 addition & 1 deletion tests/Query/QOM/QomToSql2ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ protected function assertQuery($expectedSql2, $source, $columns = [], $constrain

$result = $this->parser->convert($query);
if (is_array($expectedSql2)) {
$this->assertTrue(in_array($result, $expectedSql2), "The statement '$result' does not match an expected variation");
$this->assertContains($result, $expectedSql2, "The statement '$result' does not match an expected variation");
} else {
$this->assertEquals($expectedSql2, $result);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Query/QOM/Sql2ToQomConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testColumnsAndSelector()
$this->assertEquals('nt:unstructured', $query->getSource()->getNodeTypeName());

$cols = $query->getColumns();
$this->assertTrue(is_array($cols));
$this->assertInternalType('array', $cols);
$this->assertCount(2, $cols);

$this->assertEquals('u', $cols[0]->getselectorName());
Expand Down
4 changes: 2 additions & 2 deletions tests/Query/QueryResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function testReadPropertyContentFromResults()
{
$seekName = '/tests_general_base/multiValueProperty';

$this->assertTrue(count($this->qr->getNodes()) > 0);
$this->assertGreaterThan(0, count($this->qr->getNodes()));
foreach ($this->qr->getNodes() as $path => $node) {
if ($seekName == $path) {
break;
Expand Down Expand Up @@ -202,7 +202,7 @@ public function testCompareNumberFieldsMulti()
}

$this->assertCount(1, $rows);

// returning a string value is, perhaps suprisingly, the correct behavior.
$this->assertEquals('4 2 8', $rows[0]->getValue('data.longNumberToCompareMulti'));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Query/RowIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ public function testCountable()
$rows[] = $row;
}

$this->assertEquals(count($rows), $this->rowIterator->count());
$this->assertCount($this->rowIterator->count(), $rows);
}
}
2 changes: 1 addition & 1 deletion tests/Query/RowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testGetNode()

public function testGetPath()
{
$this->assertTrue(in_array($this->row->getPath(), $this->resultPaths), 'not one of the expected results');
$this->assertContains($this->row->getPath(), $this->resultPaths, 'not one of the expected results');
}

public function testGetScore()
Expand Down
16 changes: 8 additions & 8 deletions tests/Reading/BinaryReadMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ public function setUp()
public function testReadBinaryValue()
{
$binary = $this->binaryProperty->getBinary();
$this->assertTrue(is_resource($binary));
$this->assertInternalType('resource', $binary);
$this->assertEquals($this->decodedstring, stream_get_contents($binary));

// stream must start when getting again
$binary = $this->binaryProperty->getBinary();
$this->assertTrue(is_resource($binary));
$this->assertInternalType('resource', $binary);
$this->assertEquals($this->decodedstring, stream_get_contents($binary), 'Stream must begin at start again on second read');

// stream must not be the same
fclose($binary);
$binary = $this->binaryProperty->getBinary();
$this->assertTrue(is_resource($binary));
$this->assertInternalType('resource', $binary);
$this->assertEquals($this->decodedstring, stream_get_contents($binary), 'Stream must be different for each call, fclose should not matter');
}

Expand Down Expand Up @@ -100,7 +100,7 @@ public function testReadBinaryValues()
$vals = $binaryMulti->getValue();
$this->assertInternalType('array', $vals);
foreach ($vals as $value) {
$this->assertTrue(is_resource($value));
$this->assertInternalType('resource', $value);
$this->assertEquals($this->decodedstring, stream_get_contents($value));
}
}
Expand Down Expand Up @@ -161,8 +161,8 @@ public function testReadEmptyBinaryMultivalue()
$empty = $node->getProperty('empty_multidata');
$this->assertEquals(PropertyType::BINARY, $empty->getType());
$emptyValue = $empty->getBinary();
$this->assertTrue(is_array($emptyValue));
$this->assertTrue(count($emptyValue) === 0);
$this->assertInternalType('array', $emptyValue);
$this->assertCount(0, $emptyValue);
}

/**
Expand All @@ -174,8 +174,8 @@ public function testReadSingleBinaryMultivalue()
$single = $node->getProperty('single_multidata');
$this->assertEquals(PropertyType::BINARY, $single->getType());
$singleValue = $single->getBinary();
$this->assertTrue(is_array($singleValue));
$this->assertTrue(is_resource($singleValue[0]));
$this->assertInternalType('array', $singleValue);
$this->assertInternalType('resource', $singleValue[0]);
$contents = stream_get_contents($singleValue[0]);
$this->assertEquals($this->decodedstring, $contents);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Reading/NodeReadMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public function testGetIdentifierNonReferenceable()
public function testGetIndex()
{
$index = $this->node->getIndex();
$this->assertTrue(is_numeric($index));
$this->assertInternalType('numeric', $index);
$this->assertEquals(1, $index);
}

Expand All @@ -523,7 +523,7 @@ public function testGetReferencesAll()
$this->assertCount(2, $iterator, 'Wrong number of references to idExample');
foreach ($iterator as $prop) {
$this->assertInstanceOf(PropertyInterface::class, $prop);
$this->assertTrue(in_array($prop, $source));
$this->assertContains($prop, $source);
}
}

Expand Down Expand Up @@ -594,7 +594,7 @@ public function testGetWeakReferencesAll()
$this->assertCount(3, $iterator, 'Wrong number of weak references to weakreference_target');
foreach ($iterator as $prop) {
$this->assertInstanceOf(PropertyInterface::class, $prop);
$this->assertTrue(in_array($prop, $source, true));
$this->assertContains($prop, $source);
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Reading/PropertyReadMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ public function testGetStringMulti()
public function testGetBinary()
{
$bin = $this->valProperty->getBinary();
$this->assertTrue(is_resource($bin));
$this->assertInternalType('resource', $bin);
$str = $this->valProperty->getString();
$this->assertEquals($str, stream_get_contents($bin));
$this->assertEquals($this->valProperty->getLength(), strlen($str));

$prop = $this->node->getProperty('index.txt/jcr:content/jcr:data');
$this->assertEquals(PropertyType::BINARY, $prop->getType(), 'Expected binary type');
$bin = $prop->getValue();
$this->assertTrue(is_resource($bin));
$this->assertInternalType('resource', $bin);
$this->assertNotNull(stream_get_contents($bin));
fclose($bin);
}
Expand All @@ -227,7 +227,7 @@ public function testGetBinaryMulti()
$arr = $prop->getValue();
$this->assertInternalType('array', $arr);
foreach ($arr as $bin) {
$this->assertTrue(is_resource($bin));
$this->assertInternalType('resource', $bin);
$this->assertNotNull(stream_get_contents($bin));
}
}
Expand Down
16 changes: 8 additions & 8 deletions tests/Reading/SessionReadMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public function testGetNodes()
]);

$this->assertCount(2, $nodes);
$this->assertTrue(isset($nodes['/tests_general_base']));
$this->assertTrue(isset($nodes['/tests_general_base/numberPropertyNode']));
$this->assertArrayHasKey('/tests_general_base', $nodes);
$this->assertArrayHasKey('/tests_general_base/numberPropertyNode', $nodes);

foreach ($nodes as $key => $node) {
$this->assertInstanceOf(NodeInterface::class, $node);
Expand All @@ -115,8 +115,8 @@ public function testGetNodesTraversable()
]));

$this->assertCount(2, $nodes);
$this->assertTrue(isset($nodes['/tests_general_base']));
$this->assertTrue(isset($nodes['/tests_general_base/numberPropertyNode']));
$this->assertArrayHasKey('/tests_general_base', $nodes);
$this->assertArrayHasKey('/tests_general_base/numberPropertyNode', $nodes);

foreach ($nodes as $key => $node) {
$this->assertInstanceOf(NodeInterface::class, $node);
Expand Down Expand Up @@ -169,8 +169,8 @@ public function testGetProperties()
'/tests_general_base/../not_existing/jcr:primaryType',
]);
$this->assertCount(2, $properties);
$this->assertTrue(isset($properties['/tests_general_base/jcr:primaryType']));
$this->assertTrue(isset($properties['/tests_general_base/numberPropertyNode/jcr:primaryType']));
$this->assertArrayHasKey('/tests_general_base/jcr:primaryType', $properties);
$this->assertArrayHasKey('/tests_general_base/numberPropertyNode/jcr:primaryType', $properties);
foreach ($properties as $key => $property) {
$this->assertInstanceOf(PropertyInterface::class, $property);
$this->assertEquals($key, $property->getPath());
Expand All @@ -186,8 +186,8 @@ public function testGetPropertiesTraversable()
'/tests_general_base/../not_existing/jcr:primaryType',
]));
$this->assertCount(2, $properties);
$this->assertTrue(isset($properties['/tests_general_base/jcr:primaryType']));
$this->assertTrue(isset($properties['/tests_general_base/numberPropertyNode/jcr:primaryType']));
$this->assertArrayHasKey('/tests_general_base/jcr:primaryType', $properties);
$this->assertArrayHasKey('/tests_general_base/numberPropertyNode/jcr:primaryType', $properties);
foreach ($properties as $key => $property) {
$this->assertInstanceOf(PropertyInterface::class, $property);
$this->assertEquals($key, $property->getPath());
Expand Down
14 changes: 7 additions & 7 deletions tests/Versioning/VersionHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@ public function testGetVersionLabels()
$version = $history->getVersion('1.0');

$labels = $history->getVersionLabels($version);
$this->assertEquals(2, count($labels));
$this->assertTrue(in_array('stable', $labels));
$this->assertTrue(in_array('labelname', $labels));
$this->assertCount(2, $labels);
$this->assertContains('stable', $labels);
$this->assertContains('labelname', $labels);

$labels = $history->getVersionLabels();
$this->assertEquals(3, count($labels));
$this->assertTrue(in_array('stable', $labels));
$this->assertTrue(in_array('labelname', $labels));
$this->assertTrue(in_array('anotherlabelname', $labels));
$this->assertCount(3, $labels);
$this->assertContains('stable', $labels);
$this->assertContains('labelname', $labels);
$this->assertContains('anotherlabelname', $labels);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions tests/Writing/CopyMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ public function testCopyChildrenBinaryData()
$srcVal = $srcProp->getBinary();
$dstVal = $dstProp->getBinary();

$this->assertTrue(is_resource($srcVal), 'Failed to get src binary stream');
$this->assertTrue(is_resource($dstVal), 'Failed to get dst binary stream');
$this->assertInternalType('resource', $srcVal, 'Failed to get src binary stream');
$this->assertInternalType('resource', $dstVal, 'Failed to get dst binary stream');

$this->assertEquals(stream_get_contents($srcVal), stream_get_contents($dstVal));
}
Expand All @@ -303,13 +303,13 @@ public function testCopyChildrenBinaryDataMultivalue()
$srcVal = $srcProp->getValue();
$dstVal = $dstProp->getValue();

$this->assertTrue(is_array($srcVal), 'Failed to get src value');
$this->assertTrue(is_array($dstVal), 'Failed to get dst value');
$this->assertInternalType('array', $srcVal, 'Failed to get src value');
$this->assertInternalType('array', $dstVal, 'Failed to get dst value');

$this->assertTrue(is_resource($srcVal[0]));
$this->assertTrue(is_resource($srcVal[1]));
$this->assertTrue(is_resource($dstVal[0]));
$this->assertTrue(is_resource($dstVal[1]));
$this->assertInternalType('resource', $srcVal[0]);
$this->assertInternalType('resource', $srcVal[1]);
$this->assertInternalType('resource', $dstVal[0]);
$this->assertInternalType('resource', $dstVal[1]);

$this->assertEquals(stream_get_contents($srcVal[0]), stream_get_contents($dstVal[0]));
$this->assertEquals(stream_get_contents($srcVal[1]), stream_get_contents($dstVal[1]));
Expand Down
4 changes: 2 additions & 2 deletions tests/Writing/MixinCreatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testCreationNode()
$this->assertInstanceOf(DateTime::class, $date);
/* @var $date DateTime */
$diff = time() - $date->getTimestamp();
$this->assertTrue($diff < 60 * 10, 'jcr:created should be current date as fixture was just imported: '.$date->format('c'));
$this->assertLessThan(60 * 10, $diff, 'jcr:created should be current date as fixture was just imported: '.$date->format('c'));

// Re-read the node to be sure things got properly saved
$this->renewSession();
Expand All @@ -59,6 +59,6 @@ public function testCreationNode()
$date = $child->getPropertyValue('jcr:created');
$this->assertInstanceOf(DateTime::class, $date);
$diff = time() - $date->getTimestamp();
$this->assertTrue($diff < 60 * 10, 'jcr:created should be current date as fixture was just imported: '.$date->format('c'));
$this->assertLessThan(60 * 10, $diff, 'jcr:created should be current date as fixture was just imported: '.$date->format('c'));
}
}
6 changes: 3 additions & 3 deletions tests/Writing/NamespaceRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public function testGetPrefixes()
{
$ret = $this->nr->getPrefixes();
$this->assertInternalType('array', $ret);
$this->assertTrue(count($ret) >= count($this->nsBuiltIn));
$this->assertGreaterThanOrEqual(count($this->nsBuiltIn), count($ret));
}

public function testGetURIs()
{
$ret = $this->nr->getURIs();
$this->assertInternalType('array', $ret);
$this->assertTrue(count($ret) >= count($this->nsBuiltIn));
$this->assertGreaterThanOrEqual(count($this->nsBuiltIn), count($ret));
//we test in getURI / getPrefix if the names match
}

Expand Down Expand Up @@ -150,6 +150,6 @@ public function testIterator()
$this->assertInternalType('string', $url);
$this->assertEquals($url, $this->nr->getURI($prefix));
}
$this->assertTrue($results > 3, 'Not enough namespaces');
$this->assertGreaterThan(3, $results, 'Not enough namespaces');
}
}
Loading