Skip to content

Commit 7d260c1

Browse files
authored
Merge pull request #189 from carusogabriel/improve-assertions
Improve assertions
2 parents 9d958ba + ebc9a8a commit 7d260c1

19 files changed

+66
-66
lines changed

tests/NodeTypeDiscovery/NodeDefinitionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,24 @@ public function getRequiredPrimaryTypeNames()
108108
{
109109
$names = $this->content->getRequiredPrimaryTypeNames();
110110
$this->assertInternalType('array', $names);
111-
$this->assertTrue(1, count($names));
111+
$this->assertCount(1, $names);
112112
$this->assertEquals('nt:base', $names[0]);
113113

114114
$names = $this->hierarchyNodeDef->getRequiredPrimaryTypeNames();
115115
$this->assertInternalType('array', $names);
116-
$this->assertTrue(1, count($names));
116+
$this->assertCount(1, $names);
117117
$this->assertEquals('nt:hierarchyNode', $names[0]);
118118
}
119119
public function getRequiredPrimaryTypes()
120120
{
121121
$types = $this->content->getRequiredPrimaryTypeNames();
122122
$this->assertInternalType('array', $types);
123-
$this->assertTrue(1, count($types));
123+
$this->assertCount(1, $types);
124124
$this->assertEquals(self::$base, $types[0]);
125125

126126
$types = $this->hierarchyNodeDef->getRequiredPrimaryTypeNames();
127127
$this->assertInternalType('array', $types);
128-
$this->assertTrue(1, count($types));
128+
$this->assertCount(1, $types);
129129
$this->assertEquals(self::$hierarchyNodeType, $types[0]);
130130
}
131131

tests/Observation/ObservationManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ protected function assertFilterOnPathDeep(ObservationManagerInterface $observati
242242
$journal->next();
243243

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

tests/PhpcrUtils/CndParserTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ public function testNoStopAtEofError()
157157
{
158158
$res = $this->cndParser->parseFile(__DIR__.'/resources/cnd/no-stop-at-eof.cnd');
159159

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

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

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

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

174174
$def = $res['nodeTypes'];
175-
$this->assertTrue(isset($def['nt:file']));
175+
$this->assertArrayHasKey('nt:file', $def);
176176
/** @var $parsed NodeTypeDefinitionInterface */
177177
$parsed = $def['nt:file'];
178178
$this->assertEquals('nt:file', $parsed->getName());
@@ -190,10 +190,10 @@ public function testBigFile()
190190
*/
191191
protected function assertExampleCnd($res)
192192
{
193-
$this->assertTrue(isset($res['namespaces']));
193+
$this->assertArrayHasKey('namespaces', $res);
194194
$this->assertEquals(['ns' => 'http://namespace.com/ns'], $res['namespaces']);
195195

196-
$this->assertTrue(isset($res['nodeTypes']));
196+
$this->assertArrayHasKey('nodeTypes', $res);
197197
// get first node type
198198
reset($res['nodeTypes']);
199199
/** @var $def NodeTypeDefinitionInterface */

tests/Query/NodeViewTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ public function testCountable()
7474
$nodes[] = $node;
7575
}
7676

77-
$this->assertEquals(count($nodes), $this->nodeIterator->count());
77+
$this->assertCount($this->nodeIterator->count(), $nodes);
7878
}
7979
}

tests/Query/QOM/QomToSql2ConverterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ protected function assertQuery($expectedSql2, $source, $columns = [], $constrain
411411

412412
$result = $this->parser->convert($query);
413413
if (is_array($expectedSql2)) {
414-
$this->assertTrue(in_array($result, $expectedSql2), "The statement '$result' does not match an expected variation");
414+
$this->assertContains($result, $expectedSql2, "The statement '$result' does not match an expected variation");
415415
} else {
416416
$this->assertEquals($expectedSql2, $result);
417417
}

tests/Query/QOM/Sql2ToQomConverterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testColumnsAndSelector()
5555
$this->assertEquals('nt:unstructured', $query->getSource()->getNodeTypeName());
5656

5757
$cols = $query->getColumns();
58-
$this->assertTrue(is_array($cols));
58+
$this->assertInternalType('array', $cols);
5959
$this->assertCount(2, $cols);
6060

6161
$this->assertEquals('u', $cols[0]->getselectorName());

tests/Query/QueryResultsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function testReadPropertyContentFromResults()
146146
{
147147
$seekName = '/tests_general_base/multiValueProperty';
148148

149-
$this->assertTrue(count($this->qr->getNodes()) > 0);
149+
$this->assertGreaterThan(0, count($this->qr->getNodes()));
150150
foreach ($this->qr->getNodes() as $path => $node) {
151151
if ($seekName == $path) {
152152
break;
@@ -202,7 +202,7 @@ public function testCompareNumberFieldsMulti()
202202
}
203203

204204
$this->assertCount(1, $rows);
205-
205+
206206
// returning a string value is, perhaps suprisingly, the correct behavior.
207207
$this->assertEquals('4 2 8', $rows[0]->getValue('data.longNumberToCompareMulti'));
208208
}

tests/Query/RowIteratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ public function testCountable()
7979
$rows[] = $row;
8080
}
8181

82-
$this->assertEquals(count($rows), $this->rowIterator->count());
82+
$this->assertCount($this->rowIterator->count(), $rows);
8383
}
8484
}

tests/Query/RowTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testGetNode()
8787

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

9393
public function testGetScore()

tests/Reading/BinaryReadMethodsTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ public function setUp()
5555
public function testReadBinaryValue()
5656
{
5757
$binary = $this->binaryProperty->getBinary();
58-
$this->assertTrue(is_resource($binary));
58+
$this->assertInternalType('resource', $binary);
5959
$this->assertEquals($this->decodedstring, stream_get_contents($binary));
6060

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

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

@@ -100,7 +100,7 @@ public function testReadBinaryValues()
100100
$vals = $binaryMulti->getValue();
101101
$this->assertInternalType('array', $vals);
102102
foreach ($vals as $value) {
103-
$this->assertTrue(is_resource($value));
103+
$this->assertInternalType('resource', $value);
104104
$this->assertEquals($this->decodedstring, stream_get_contents($value));
105105
}
106106
}
@@ -161,8 +161,8 @@ public function testReadEmptyBinaryMultivalue()
161161
$empty = $node->getProperty('empty_multidata');
162162
$this->assertEquals(PropertyType::BINARY, $empty->getType());
163163
$emptyValue = $empty->getBinary();
164-
$this->assertTrue(is_array($emptyValue));
165-
$this->assertTrue(count($emptyValue) === 0);
164+
$this->assertInternalType('array', $emptyValue);
165+
$this->assertCount(0, $emptyValue);
166166
}
167167

168168
/**
@@ -174,8 +174,8 @@ public function testReadSingleBinaryMultivalue()
174174
$single = $node->getProperty('single_multidata');
175175
$this->assertEquals(PropertyType::BINARY, $single->getType());
176176
$singleValue = $single->getBinary();
177-
$this->assertTrue(is_array($singleValue));
178-
$this->assertTrue(is_resource($singleValue[0]));
177+
$this->assertInternalType('array', $singleValue);
178+
$this->assertInternalType('resource', $singleValue[0]);
179179
$contents = stream_get_contents($singleValue[0]);
180180
$this->assertEquals($this->decodedstring, $contents);
181181
}

0 commit comments

Comments
 (0)