markTestSkipped('LDAP is not installed'); } } public function testBindSuccess() { $zendLdap = $this->getMockBuilder(Ldap::class)->disableOriginalConstructor()->setMethods(['bind'])->getMock(); $zendLdap->expects($this->once())->method('bind')->willReturnSelf(); $user = new User(); $sut = new TestLdapDriver($zendLdap); $result = $sut->bind($user, 'test123'); self::assertTrue($result); } public function testBindException() { $zendLdap = $this->getMockBuilder(Ldap::class)->disableOriginalConstructor()->setMethods(['bind'])->getMock(); $zendLdap->expects($this->once())->method('bind')->willThrowException(new LdapException()); $user = new User(); $sut = new TestLdapDriver($zendLdap); $result = $sut->bind($user, 'test123'); self::assertFalse($result); } public function testSearchSuccess() { $zendLdap = $this->getMockBuilder(Ldap::class)->disableOriginalConstructor()->setMethods(['bind', 'searchEntries'])->getMock(); $zendLdap->expects($this->once())->method('bind'); $zendLdap->expects($this->once())->method('searchEntries')->willReturn([1, 2, 3]); $sut = new TestLdapDriver($zendLdap); $result = $sut->search('', '', []); self::assertEquals(['count' => 3, 1, 2, 3], $result); } /** * @expectedException \App\Ldap\LdapDriverException * @expectedExceptionMessage An error occurred with the search operation. */ public function testSearchException() { $zendLdap = $this->getMockBuilder(Ldap::class)->disableOriginalConstructor()->setMethods(['bind', 'searchEntries'])->getMock(); $zendLdap->expects($this->once())->method('bind'); $zendLdap->expects($this->once())->method('searchEntries')->willThrowException( new LdapException($zendLdap, '', LdapException::LDAP_SERVER_DOWN) ); $sut = new TestLdapDriver($zendLdap); $sut->search('', '', []); } } class TestLdapDriver extends LdapDriver { public function __construct(Ldap $ldap) { $this->driver = $ldap; } }