wp = $this->make(new WPFunctions, [ 'isPluginActive' => function($name) { if ($name === 'automatewoo/automatewoo.php') { return true; } return false; }, ]); $this->subscribersRepository = $this->createMock(SubscribersRepository::class); $this->subscriberFactory = new SubscriberFactory(); } public function testSetup() { $wp = $this->make(new WPFunctions, [ 'isPluginActive' => function($name) { if ($name === 'automatewoo/automatewoo.php') { return true; } return false; }, 'addAction' => Expected::exactly(1), ]); $automateWooHooksPartialMock = $this->getMockBuilder(AutomateWooHooks::class) ->setConstructorArgs([$this->subscribersRepository, $wp]) ->onlyMethods(['areMethodsAvailable']) ->getMock(); $automateWooHooksPartialMock->expects($this->once())->method('areMethodsAvailable')->willReturn(true); $automateWooHooksPartialMock->setup(); } public function testOptsOutUnsubscribedSubscriber() { $unsubscribedSubscriber = $this->subscriberFactory ->withEmail('unsubscribedUser@mailpoet.com') ->withStatus(SubscriberEntity::STATUS_UNSUBSCRIBED)->create(); $this->subscribersRepository->method('findOneById')->willReturn($unsubscribedSubscriber); $automateWooHooksPartialMock = $this->getMockBuilder(AutomateWooHooks::class) ->setConstructorArgs([$this->subscribersRepository, $this->wp]) ->onlyMethods(['optOutSubscriber']) ->getMock(); $automateWooHooksPartialMock->expects($this->once())->method('optOutSubscriber'); $automateWooHooksPartialMock->maybeOptOutSubscriber((int)$unsubscribedSubscriber->getId()); } public function testDoesNotOptOutSubscribedSubscriber() { $subscribedSubscriber = $this->subscriberFactory ->withEmail('subscribedUser@mailpoet.com') ->withStatus(SubscriberEntity::STATUS_SUBSCRIBED)->create(); $this->subscribersRepository->method('findOneById')->willReturn($subscribedSubscriber); $automateWooHooksPartialMock = $this->getMockBuilder(AutomateWooHooks::class) ->setConstructorArgs([$this->subscribersRepository, $this->wp]) ->onlyMethods(['optOutSubscriber']) ->getMock(); $automateWooHooksPartialMock->expects($this->never())->method('optOutSubscriber'); $automateWooHooksPartialMock->maybeOptOutSubscriber((int)$subscribedSubscriber->getId()); } }