/** * Test create lazy ask password getter */ public function testCreateLazyAskPasswordGetter() { $lazyGetter = AskPasswordGetter::createLazyGetter(); $this->assertInstanceOf('Deployer\\Server\\Password\\CallablePasswordGetter', $lazyGetter); $context = $this->getMock('Deployer\\Task\\Context', ['getInput', 'getOutput'], [], '', false); $context->expects($this->any())->method('getInput')->will($this->returnValue($this->input)); $context->expects($this->any())->method('getOutput')->will($this->returnValue($this->output)); // Push own context Context::push($context); $lazyGetter->getPassword('host', 'user'); // Pop own context Context::pop(); }
/** * Check password valid * * @param mixed $password * * @return mixed */ private function checkPassword($password) { if (is_null($password)) { return AskPasswordGetter::createLazyGetter(); } if (is_scalar($password)) { return $password; } if (is_object($password) && $password instanceof PasswordGetterInterface) { return $password; } // Invalid password throw new \InvalidArgumentException(sprintf('The password should be a string or PasswordGetterInterface instances, but "%s" given.', is_object($password) ? get_class($password) : gettype($password))); }