コード例 #1
0
ファイル: Challenger.php プロジェクト: acmephp/symfony-bundle
 /**
  * Request and check a domain.
  *
  * @param string $domain
  *
  * @throws \Exception
  */
 public function challengeDomain($domain)
 {
     Assert::stringNotEmpty($domain, 'challengeDomain::$domain expected a non-empty string. Got: %s');
     $challenge = $this->client->requestChallenge($domain);
     $challengeEvent = new ChallengeEvent($challenge);
     $this->dispatcher->dispatch(AcmePhpBundleEvents::CHALLENGE_REQUESTED, $challengeEvent);
     try {
         $this->client->checkChallenge($challenge);
         $this->dispatcher->dispatch(AcmePhpBundleEvents::CHALLENGE_ACCEPTED, $challengeEvent);
     } catch (\Exception $e) {
         $this->dispatcher->dispatch(AcmePhpBundleEvents::CHALLENGE_REJECTED, $challengeEvent);
         throw $e;
     } finally {
         $this->dispatcher->dispatch(AcmePhpBundleEvents::CHALLENGE_CHECKED, $challengeEvent);
     }
 }
コード例 #2
0
 /**
  * @expectedException \Exception
  */
 public function test challengeDomain triggers rejected event()
 {
     $dummyDomain = uniqid();
     $dummyChallenge = $this->prophesize(Challenge::class)->reveal();
     $this->mockClient->requestChallenge($dummyDomain)->shouldBeCalled()->willReturn($dummyChallenge);
     $this->mockClient->checkChallenge($dummyChallenge)->shouldBeCalled()->willThrow(new \Exception());
     $this->mockDispatcher->dispatch('acme_php.challenge.requested', Argument::that(function ($item) use($dummyChallenge) {
         $this->assertInstanceOf(ChallengeEvent::class, $item);
         $this->assertSame($dummyChallenge, $item->getChallenge());
         return true;
     }))->shouldBeCalled();
     $this->mockDispatcher->dispatch('acme_php.challenge.accepted', Argument::any())->shouldNotBeCalled();
     $this->mockDispatcher->dispatch('acme_php.challenge.rejected', Argument::that(function ($item) use($dummyChallenge) {
         $this->assertInstanceOf(ChallengeEvent::class, $item);
         $this->assertSame($dummyChallenge, $item->getChallenge());
         return true;
     }))->shouldBeCalled();
     $this->mockDispatcher->dispatch('acme_php.challenge.checked', Argument::that(function ($item) use($dummyChallenge) {
         $this->assertInstanceOf(ChallengeEvent::class, $item);
         $this->assertSame($dummyChallenge, $item->getChallenge());
         return true;
     }))->shouldBeCalled();
     $this->service->challengeDomain($dummyDomain);
 }