Files
piratepoet/mailpoet/tests/integration/API/JSON/ResponseBuilders/SegmentsResponseBuilderTest.php
Rodrigo Primo a1f57361c5 Replace expect()->array() with verify()->isArray()
codeception/verify 2.1 removed support for expect()->array() so we need
to replace it with verify()->isArray().

[MAILPOET-5664]
2023-10-24 08:58:22 +03:00

61 lines
2.3 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\API\JSON\ResponseBuilders;
use MailPoet\DI\ContainerWrapper;
use MailPoet\Entities\SegmentEntity;
use MailPoet\Entities\SubscriberEntity;
use MailPoet\Entities\SubscriberSegmentEntity;
use MailPoetVendor\Doctrine\ORM\EntityManager;
class SegmentsResponseBuilderTest extends \MailPoetTest {
public function testItBuildsResponse() {
$name = 'Response Builder Test';
$description = 'Testing description';
$di = ContainerWrapper::getInstance();
$em = $di->get(EntityManager::class);
$segment = new SegmentEntity($name, SegmentEntity::TYPE_DEFAULT, $description);
$em->persist($segment);
$em->flush();
$responseBuilder = $di->get(SegmentsResponseBuilder::class);
$response = $responseBuilder->build($segment);
verify($response['name'])->equals($name);
verify($response['type'])->equals(SegmentEntity::TYPE_DEFAULT);
verify($response['description'])->equals($description);
verify($response)->arrayHasKey('id');
verify($response)->arrayHasKey('created_at');
verify($response)->arrayHasKey('updated_at');
verify($response)->arrayHasKey('deleted_at');
$em->remove($segment);
$em->flush();
}
public function testItBuildsListingsResponse() {
$name = 'Response Listings Builder Test';
$description = 'Testing description';
$di = ContainerWrapper::getInstance();
$em = $di->get(EntityManager::class);
$segment = new SegmentEntity($name, SegmentEntity::TYPE_DEFAULT, $description);
$em->persist($segment);
$subscriber = new SubscriberEntity();
$subscriber->setStatus(SubscriberEntity::STATUS_SUBSCRIBED);
$subscriber->setEmail('a@example.com');
$em->persist($subscriber);
$subscriberSegment = new SubscriberSegmentEntity($segment, $subscriber, SubscriberEntity::STATUS_SUBSCRIBED);
$em->persist($subscriberSegment);
$em->flush();
$responseBuilder = $di->get(SegmentsResponseBuilder::class);
$response = $responseBuilder->buildForListing([$segment]);
verify($response)->isArray();
verify($response[0]['name'])->equals($name);
verify($response[0]['type'])->equals(SegmentEntity::TYPE_DEFAULT);
expect($response[0]['subscribers_url'])->startsWith('http');
verify($response[0]['subscribers_count']['subscribed'])->equals('1');
}
}