-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: factory static to controller + change version of phpunit + add …
…new test
- Loading branch information
1 parent
f0b2254
commit 37b87de
Showing
13 changed files
with
424 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"version":1,"defects":{"Unit\\MailchimpMailerTest::testSubscribe":3,"Unit\\MailjetMailerTest::testSubscribe":4,"Unit\\MailchimpMailerTest::testSubscribeWithMemberExist":3,"Unit\\MailchimpMailerTest::testSubscribeWithoutId":3,"Unit\\BrevoMailerTest::testSubscribeWithoutContactExist":3,"Unit\\BrevoMailerTest::testSubscribeWithContactExist":3,"Unit\\YmlpMailerTest::testSubscribe":3,"Unit\\YmlpMailerTest::testSubscribeWithoutCode":4},"times":{"Unit\\BrevoMailerTestCase::testSubscribe":0.003,"Unit\\BrevoMailerTestCase::testSendTransactionalEmail":0,"Unit\\BrevoMailerTestCase::testExceptionApiKey":0,"Unit\\BrevoMailerTest::testSubscribe":0.003,"Unit\\BrevoMailerTest::testSendTransactionalEmail":0,"Unit\\BrevoMailerTest::testExceptionApiKey":0,"Unit\\MailchimpMailerTest::testSubscribe":0,"Unit\\MailchimpMailerTest::testSendTransactionalEmail":0,"Unit\\MailchimpMailerTest::testExceptionApiKey":0,"Unit\\MailjetMailerTest::testSubscribe":0,"Unit\\MailjetMailerTest::testSendTransactionalEmail":0,"Unit\\MailjetMailerTest::testExceptionApiKey":0,"Unit\\YmlpMailerTest::testSubscribe":0,"Unit\\YmlpMailerTest::testSendTransactionalEmail":0,"Unit\\MailchimpMailerTest::testSubscribeWithMemberExist":0,"Unit\\MailchimpMailerTest::testSubscribeWithoutId":0,"Unit\\MailjetMailerTest::testSubscribeWithCodeError":0,"Unit\\BrevoMailerTest::testSubscribeWithoutContactExist":0,"Unit\\BrevoMailerTest::testSubscribeWithoutId":0,"Unit\\BrevoMailerTest::testSubscribeWithContactExist":0,"Unit\\YmlpMailerTest::testSubscribeWithoutCode":0}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
convertDeprecationsToExceptions="false" | ||
> | ||
<php> | ||
<ini name="display_errors" value="1" /> | ||
<ini name="error_reporting" value="-1" /> | ||
<server name="SHELL_VERBOSITY" value="-1" /> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="Project Test Suite"> | ||
<directory>tests/Unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage cacheDirectory="coverage" | ||
includeUncoveredFiles="true" | ||
processUncoveredFiles="true" | ||
pathCoverage="false" | ||
ignoreDeprecatedCodeUnits="true" | ||
disableCodeCoverageIgnore="true"> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
<report> | ||
<text outputFile="php://stdout"/> | ||
<clover outputFile="coverage/clover.xml"/> | ||
<cobertura outputFile="coverage/cobertura.xml"/> | ||
</report> | ||
</coverage> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SubscribeMe; | ||
|
||
use SubscribeMe\Subscriber\SubscriberInterface; | ||
|
||
interface SubscriberFactoryInterface | ||
{ | ||
/** | ||
* @param string $platform | ||
* @return SubscriberInterface | ||
*/ | ||
public function createFor(string $platform): SubscriberInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,13 @@ | |
use Http\Discovery\Psr17Factory; | ||
use Http\Mock\Client; | ||
use JsonException; | ||
use Nyholm\Psr7\Response; | ||
use PHPUnit\Framework\TestCase; | ||
use SubscribeMe\Exception\MissingApiCredentialsException; | ||
use SubscribeMe\Subscriber\BrevoSubscriber; | ||
use SubscribeMe\ValueObject\EmailAddress; | ||
|
||
class BrevoMailerTestCase extends TestCase | ||
class BrevoMailerTest extends TestCase | ||
{ | ||
/** | ||
* @throws JsonException | ||
|
@@ -21,6 +22,106 @@ public function testSubscribe(): void | |
{ | ||
$client = new Client(); | ||
$factory = new Psr17Factory(); | ||
|
||
$response = new Response(200, [], json_encode(['id' => 1], JSON_THROW_ON_ERROR)); | ||
$client->setDefaultResponse($response); | ||
|
||
$brevoSubscriber = new BrevoSubscriber($client, $factory, $factory); | ||
|
||
$email = '[email protected]'; | ||
$options = [ | ||
'FNAME' => 'Elly', | ||
'LNAME' => 'Roger', | ||
'COUNTRY' => [ | ||
'India', | ||
'China' | ||
] | ||
]; | ||
|
||
$brevoSubscriber->setContactListId('3,5'); | ||
$brevoSubscriber->setApiKey('928f601b-5476-4480-8eb0-c8d979f3b68f'); | ||
$returnCode = $brevoSubscriber->subscribe($email, $options); | ||
|
||
$requests = $client->getRequests(); | ||
|
||
$body = [ | ||
'updateEnabled' => true, | ||
'email' => $email, | ||
'listIds' => [3,5], | ||
'attributes' => $options | ||
]; | ||
$body = json_encode($body); | ||
|
||
$this->assertEquals(1, $returnCode); | ||
$this->assertCount(1, $requests); | ||
$content = $requests[0]->getBody()->getContents(); | ||
$this->assertEquals('application/json', $requests[0]->getHeaders()['Content-Type'][0]); | ||
$this->assertEquals('928f601b-5476-4480-8eb0-c8d979f3b68f', $requests[0]->getHeaders()['api-key'][0]); | ||
$this->assertEquals('rezozero/subscribeme', $requests[0]->getHeaders()['User-Agent'][0]); | ||
$this->assertEquals('POST', $requests[0]->getMethod()); | ||
$this->assertJsonStringEqualsJsonString($body ?: '{}', $content); | ||
$this->assertEquals('api.brevo.com', $requests[0]->getUri()->getHost()); | ||
} | ||
|
||
/** | ||
* @throws JsonException | ||
*/ | ||
public function testSubscribeWithContactExist(): void | ||
{ | ||
$client = new Client(); | ||
$factory = new Psr17Factory(); | ||
|
||
$response = new Response(400, [], json_encode(['message' => 'Contact already exist'], JSON_THROW_ON_ERROR)); | ||
$client->setDefaultResponse($response); | ||
|
||
$brevoSubscriber = new BrevoSubscriber($client, $factory, $factory); | ||
|
||
$email = '[email protected]'; | ||
$options = [ | ||
'FNAME' => 'Elly', | ||
'LNAME' => 'Roger', | ||
'COUNTRY' => [ | ||
'India', | ||
'China' | ||
] | ||
]; | ||
|
||
$brevoSubscriber->setContactListId('3,5'); | ||
$brevoSubscriber->setApiKey('928f601b-5476-4480-8eb0-c8d979f3b68f'); | ||
$returnCode = $brevoSubscriber->subscribe($email, $options); | ||
|
||
$requests = $client->getRequests(); | ||
|
||
$body = [ | ||
'updateEnabled' => true, | ||
'email' => $email, | ||
'listIds' => [3,5], | ||
'attributes' => $options | ||
]; | ||
$body = json_encode($body); | ||
|
||
$this->assertTrue($returnCode); | ||
$this->assertCount(1, $requests); | ||
$content = $requests[0]->getBody()->getContents(); | ||
$this->assertEquals('application/json', $requests[0]->getHeaders()['Content-Type'][0]); | ||
$this->assertEquals('928f601b-5476-4480-8eb0-c8d979f3b68f', $requests[0]->getHeaders()['api-key'][0]); | ||
$this->assertEquals('rezozero/subscribeme', $requests[0]->getHeaders()['User-Agent'][0]); | ||
$this->assertEquals('POST', $requests[0]->getMethod()); | ||
$this->assertJsonStringEqualsJsonString($body ?: '{}', $content); | ||
$this->assertEquals('api.brevo.com', $requests[0]->getUri()->getHost()); | ||
} | ||
|
||
/** | ||
* @throws JsonException | ||
*/ | ||
public function testSubscribeWithoutId(): void | ||
{ | ||
$client = new Client(); | ||
$factory = new Psr17Factory(); | ||
|
||
$response = new Response(400); | ||
$client->setDefaultResponse($response); | ||
|
||
$brevoSubscriber = new BrevoSubscriber($client, $factory, $factory); | ||
|
||
$email = '[email protected]'; | ||
|
@@ -35,7 +136,7 @@ public function testSubscribe(): void | |
|
||
$brevoSubscriber->setContactListId('3,5'); | ||
$brevoSubscriber->setApiKey('928f601b-5476-4480-8eb0-c8d979f3b68f'); | ||
$brevoSubscriber->subscribe($email, $options); | ||
$returnCode = $brevoSubscriber->subscribe($email, $options); | ||
|
||
$requests = $client->getRequests(); | ||
|
||
|
@@ -47,6 +148,7 @@ public function testSubscribe(): void | |
]; | ||
$body = json_encode($body); | ||
|
||
$this->assertFalse($returnCode); | ||
$this->assertCount(1, $requests); | ||
$content = $requests[0]->getBody()->getContents(); | ||
$this->assertEquals('application/json', $requests[0]->getHeaders()['Content-Type'][0]); | ||
|
Oops, something went wrong.