Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Use better assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbundyra committed Apr 12, 2018
1 parent c79d769 commit 125afd3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
30 changes: 15 additions & 15 deletions test/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testGetNonExistentAttribute()
$this->assertNull($value);
$array = Attribute::getAttribute($data, 'uid2');
$this->assertInternalType('array', $array);
$this->assertEquals(0, count($array));
$this->assertCount(0, $array);
}

public function testGetAttributeWithWrongIndexType()
Expand All @@ -84,7 +84,7 @@ public function testGetAttributeArray()
$data = ['uid' => ['value']];
$value = Attribute::getAttribute($data, 'uid');
$this->assertInternalType('array', $value);
$this->assertEquals(1, count($value));
$this->assertCount(1, $value);
$this->assertContains('value', $value);
}

Expand All @@ -94,7 +94,7 @@ public function testSimpleSetAttribute()
Attribute::setAttribute($data, 'uid', 'new', false);
$this->assertArrayHasKey('uid', $data);
$this->assertInternalType('array', $data['uid']);
$this->assertEquals(1, count($data['uid']));
$this->assertCount(1, $data['uid']);
$this->assertContains('new', $data['uid']);
}

Expand All @@ -104,7 +104,7 @@ public function testSimpleOverwriteAttribute()
Attribute::setAttribute($data, 'uid', 'new', false);
$this->assertArrayHasKey('uid', $data);
$this->assertInternalType('array', $data['uid']);
$this->assertEquals(1, count($data['uid']));
$this->assertCount(1, $data['uid']);
$this->assertContains('new', $data['uid']);
}

Expand All @@ -114,7 +114,7 @@ public function testSimpleAppendAttribute()
Attribute::setAttribute($data, 'uid', 'new', true);
$this->assertArrayHasKey('uid', $data);
$this->assertInternalType('array', $data['uid']);
$this->assertEquals(2, count($data['uid']));
$this->assertCount(2, $data['uid']);
$this->assertContains('old', $data['uid']);
$this->assertContains('new', $data['uid']);
$this->assertEquals('old', $data['uid'][0]);
Expand All @@ -141,7 +141,7 @@ public function testArraySetAttribute()
Attribute::setAttribute($data, 'uid', ['new1', 'new2'], false);
$this->assertArrayHasKey('uid', $data);
$this->assertInternalType('array', $data['uid']);
$this->assertEquals(2, count($data['uid']));
$this->assertCount(2, $data['uid']);
$this->assertContains('new1', $data['uid']);
$this->assertContains('new2', $data['uid']);
$this->assertEquals('new1', $data['uid'][0]);
Expand All @@ -154,7 +154,7 @@ public function testArrayOverwriteAttribute()
Attribute::setAttribute($data, 'uid', ['new1', 'new2'], false);
$this->assertArrayHasKey('uid', $data);
$this->assertInternalType('array', $data['uid']);
$this->assertEquals(2, count($data['uid']));
$this->assertCount(2, $data['uid']);
$this->assertContains('new1', $data['uid']);
$this->assertContains('new2', $data['uid']);
$this->assertEquals('new1', $data['uid'][0]);
Expand All @@ -167,7 +167,7 @@ public function testArrayAppendAttribute()
Attribute::setAttribute($data, 'uid', ['new1', 'new2'], true);
$this->assertArrayHasKey('uid', $data);
$this->assertInternalType('array', $data['uid']);
$this->assertEquals(3, count($data['uid']));
$this->assertCount(3, $data['uid']);
$this->assertContains('old', $data['uid']);
$this->assertContains('new1', $data['uid']);
$this->assertContains('new2', $data['uid']);
Expand Down Expand Up @@ -265,7 +265,7 @@ public function testSetDateTimeValueIllegal()
$ts = 'dummy';
$data = [];
Attribute::setDateTimeAttribute($data, 'ts', $ts, false);
$this->assertEquals(0, count($data['ts']));
$this->assertCount(0, $data['ts']);
}

public function testGetDateTimeValueFromLocal()
Expand Down Expand Up @@ -331,7 +331,7 @@ public function testRemoveAttributeValueSimple()
Attribute::removeFromAttribute($data, 'test', 'value2');
$this->assertArrayHasKey('test', $data);
$this->assertInternalType('array', $data['test']);
$this->assertEquals(3, count($data['test']));
$this->assertCount(3, $data['test']);
$this->assertContains('value1', $data['test']);
$this->assertContains('value3', $data['test']);
$this->assertNotContains('value2', $data['test']);
Expand All @@ -343,7 +343,7 @@ public function testRemoveAttributeValueArray()
Attribute::removeFromAttribute($data, 'test', ['value1', 'value2']);
$this->assertArrayHasKey('test', $data);
$this->assertInternalType('array', $data['test']);
$this->assertEquals(2, count($data['test']));
$this->assertCount(2, $data['test']);
$this->assertContains('value3', $data['test']);
$this->assertNotContains('value1', $data['test']);
$this->assertNotContains('value2', $data['test']);
Expand All @@ -355,7 +355,7 @@ public function testRemoveAttributeMultipleValueSimple()
Attribute::removeFromAttribute($data, 'test', 'value3');
$this->assertArrayHasKey('test', $data);
$this->assertInternalType('array', $data['test']);
$this->assertEquals(2, count($data['test']));
$this->assertCount(2, $data['test']);
$this->assertContains('value1', $data['test']);
$this->assertContains('value2', $data['test']);
$this->assertNotContains('value3', $data['test']);
Expand All @@ -367,7 +367,7 @@ public function testRemoveAttributeMultipleValueArray()
Attribute::removeFromAttribute($data, 'test', ['value1', 'value3']);
$this->assertArrayHasKey('test', $data);
$this->assertInternalType('array', $data['test']);
$this->assertEquals(1, count($data['test']));
$this->assertCount(1, $data['test']);
$this->assertContains('value2', $data['test']);
$this->assertNotContains('value1', $data['test']);
$this->assertNotContains('value3', $data['test']);
Expand All @@ -379,7 +379,7 @@ public function testRemoveAttributeValueBoolean()
Attribute::removeFromAttribute($data, 'test', false);
$this->assertArrayHasKey('test', $data);
$this->assertInternalType('array', $data['test']);
$this->assertEquals(2, count($data['test']));
$this->assertCount(2, $data['test']);
$this->assertContains('TRUE', $data['test']);
$this->assertNotContains('FALSE', $data['test']);
}
Expand All @@ -390,7 +390,7 @@ public function testRemoveAttributeValueInteger()
Attribute::removeFromAttribute($data, 'test', [2, 4]);
$this->assertArrayHasKey('test', $data);
$this->assertInternalType('array', $data['test']);
$this->assertEquals(2, count($data['test']));
$this->assertCount(2, $data['test']);
$this->assertContains('1', $data['test']);
$this->assertContains('3', $data['test']);
$this->assertNotContains('2', $data['test']);
Expand Down
2 changes: 1 addition & 1 deletion test/Node/AttributeIterationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testSimpleIteration()
$i++;
}
$this->assertEquals(5, $i);
$this->assertEquals($i, count($node));
$this->assertCount($i, $node);
$this->assertEquals([
'boolean' => [true, false],
'cn' => ['name'],
Expand Down
12 changes: 6 additions & 6 deletions test/Node/ChildrenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testGetChildrenOnAttachedNode()
$node = $this->getLDAP()->getBaseNode();
$children = $node->getChildren();
$this->assertInstanceOf('Zend\Ldap\Node\ChildrenIterator', $children);
$this->assertEquals(6, count($children));
$this->assertCount(6, $children);
$this->assertInstanceOf('Zend\Ldap\Node', $children['ou=Node']);
}

Expand All @@ -44,14 +44,14 @@ public function testGetChildrenOnDetachedNode()
$node->detachLDAP();
$children = $node->getChildren();
$this->assertInstanceOf('Zend\Ldap\Node\ChildrenIterator', $children);
$this->assertEquals(0, count($children));
$this->assertCount(0, $children);

$node->attachLDAP($this->getLDAP());
$node->reload();
$children = $node->getChildren();

$this->assertInstanceOf('Zend\Ldap\Node\ChildrenIterator', $children);
$this->assertEquals(6, count($children));
$this->assertCount(6, $children);
$this->assertInstanceOf('Zend\Ldap\Node', $children['ou=Node']);
}

Expand Down Expand Up @@ -122,20 +122,20 @@ public function testChildrenCollectionSerialization()

$children = $node->getChildren();
$this->assertTrue($node->hasChildren());
$this->assertEquals(2, count($children));
$this->assertCount(2, $children);

$string = serialize($node);
$node2 = unserialize($string);

$children2 = $node2->getChildren();
$this->assertTrue($node2->hasChildren());
$this->assertEquals(2, count($children2));
$this->assertCount(2, $children2);

$node2->attachLDAP($this->getLDAP());

$children2 = $node2->getChildren();
$this->assertTrue($node2->hasChildren());
$this->assertEquals(2, count($children2));
$this->assertCount(2, $children2);

$node = $this->getLDAP()->getNode($this->createDn('ou=Node,'));
$this->assertTrue($node->hasChildren());
Expand Down
10 changes: 5 additions & 5 deletions test/Node/OfflineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function testGetSetAndDeleteMethods()
$this->assertTrue($node->existsAttribute('key', true));
$this->assertTrue($node->existsAttribute('key', false));
$node->deleteAttribute('key');
$this->assertEquals(0, count($node->getAttribute('key')));
$this->assertCount(0, $node->getAttribute('key'));
$this->assertTrue($node->existsAttribute('key', true));
$this->assertFalse($node->existsAttribute('key', false));

Expand All @@ -286,7 +286,7 @@ public function testGetSetAndDeleteMethods()
$this->assertTrue($node->existsAttribute('key', true));
$this->assertTrue($node->existsAttribute('key', false));
$node->deleteAttribute('key');
$this->assertEquals(0, count($node->getAttribute('key')));
$this->assertCount(0, $node->getAttribute('key'));
$this->assertTrue($node->existsAttribute('key', true));
$this->assertFalse($node->existsAttribute('key', false));

Expand All @@ -295,7 +295,7 @@ public function testGetSetAndDeleteMethods()
$this->assertTrue($node->existsAttribute('userPassword', true));
$this->assertTrue($node->existsAttribute('userPassword', false));
$node->deleteAttribute('userPassword');
$this->assertEquals(0, count($node->getAttribute('userPassword')));
$this->assertCount(0, $node->getAttribute('userPassword'));
$this->assertTrue($node->existsAttribute('userPassword', true));
$this->assertFalse($node->existsAttribute('userPassword', false));
}
Expand All @@ -308,7 +308,7 @@ public function testOverloading()
$this->assertEquals('value1', $node->key[0]);
$this->assertTrue(isset($node->key));
unset($node->key);
$this->assertEquals(0, count($node->key));
$this->assertCount(0, $node->key);
$this->assertFalse(isset($node->key));
}

Expand Down Expand Up @@ -345,7 +345,7 @@ public function testArrayAccess()
$this->assertEquals('value1', $node['key'][0]);
$this->assertTrue(isset($node['key']));
unset($node['key']);
$this->assertEquals(0, count($node['key']));
$this->assertCount(0, $node['key']);
$this->assertFalse(isset($node['key']));
}

Expand Down
12 changes: 6 additions & 6 deletions test/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testGetSingleEntry()
$this->assertEquals($dn, $entry["dn"]);
$this->assertArrayHasKey('ou', $entry);
$this->assertContains('Test1', $entry['ou']);
$this->assertEquals(1, count($entry['ou']));
$this->assertCount(1, $entry['ou']);
}

public function testGetSingleIllegalEntry()
Expand Down Expand Up @@ -92,7 +92,7 @@ public function testResultIteration()
Ldap\Ldap::SEARCH_SCOPE_SUB
);
$this->assertEquals(9, $items->count());
$this->assertEquals(9, count($items));
$this->assertCount(9, $items);

$i = 0;
foreach ($items as $key => $item) {
Expand Down Expand Up @@ -125,7 +125,7 @@ public function testSearchEntriesShortcut()
Ldap\Ldap::SEARCH_SCOPE_SUB
);
$this->assertInternalType("array", $entries);
$this->assertEquals(9, count($entries));
$this->assertCount(9, $entries);
}

/**
Expand Down Expand Up @@ -231,7 +231,7 @@ public function testSearchEntriesShortcutWithDnObjectAndFilterObject()

$entries = $this->getLDAP()->searchEntries($filter, $dn, Ldap\Ldap::SEARCH_SCOPE_SUB);
$this->assertInternalType("array", $entries);
$this->assertEquals(9, count($entries));
$this->assertCount(9, $entries);
}

public function testGetSingleEntryWithDnObject()
Expand Down Expand Up @@ -365,7 +365,7 @@ public function testSearchEntriesShortcutWithOptionsArray()
'baseDn' => getenv('TESTS_ZEND_LDAP_WRITEABLE_SUBTREE'),
'scope' => Ldap\Ldap::SEARCH_SCOPE_SUB
]);
$this->assertEquals(9, count($items));
$this->assertCount(9, $items);
}

/**
Expand Down Expand Up @@ -434,7 +434,7 @@ public function testSearchNothingToArray()
'uid'
);
$entries = $entries->toArray();
$this->assertEquals(0, count($entries));
$this->assertCount(0, $entries);
$i = 0;
foreach ($entries as $key => $item) {
$i++;
Expand Down

0 comments on commit 125afd3

Please sign in to comment.