/** * setOptions * * Set the adapter chain options. * * @param array $options The adapters configuration options. * * @return $this */ public function setOptions(array $options = []) { if (isset($options['identity'])) { $this->setIdentity($options['identity']); unset($options['identity']); } if (isset($options['credential'])) { $this->setCredential($options['credential']); unset($options['credential']); } if (isset($options['password_strategy'])) { $this->setPasswordStrategy($options['password_strategy']); unset($options['password_strategy']); } parent::setOptions($options); return $this; }
public function testAuthenticateReturnsSuccessfulResultForValidIdentityAndCredential() { $adapterChain = new AdapterChain([]); $identity = '*****@*****.**'; $credential = 'Password123'; /** @var ChainableAdapterInterface[]|\PHPUnit_Framework_MockObject_Stub[] $adapters */ $adapters = [$this->createChainableAdapterMock('foo'), $this->createChainableAdapterMock('bar'), $this->createChainableAdapterMock('baz')]; $failure = $this->getMockBuilder(Result::class)->disableOriginalConstructor()->getMock(); $failure->expects($this->once())->method('getCode')->will($this->returnValue(Result::FAILURE)); $success = $this->getMockBuilder(Result::class)->disableOriginalConstructor()->getMock(); $success->expects($this->once())->method('getCode')->will($this->returnValue(Result::SUCCESS)); $adapters[0]->expects($this->once())->method('setIdentity')->with($identity); $adapters[0]->expects($this->once())->method('setCredential')->with($credential); $adapters[0]->expects($this->once())->method('authenticate')->will($this->returnValue($failure)); $adapters[1]->expects($this->once())->method('setIdentity')->with($identity); $adapters[1]->expects($this->once())->method('setCredential')->with($credential); $adapters[1]->expects($this->once())->method('authenticate')->will($this->returnValue($success)); $adapterChain->setIdentity($identity); $adapterChain->setCredential($credential); $adapterChain->setAdapters($adapters); $result = $adapterChain->authenticate(); $this->assertSame($success, $result); }