Skip to content

Commit bd7a0a8

Browse files
Updated for PHP 8. Tested most with Unit Tests.
Recommend full testing my maintainer. On branch updated-for-php8 Changes to be committed: modified: .gitignore new file: .phpunit.result.cache modified: composer.json modified: phpunit.xml new file: phpunit.xml.bak modified: tests/BatchTest.php modified: tests/CampaignsTest.php modified: tests/SegmentsTest.php modified: tests/SubscribersTest.php modified: tests/bootstrap.php
1 parent 71df4c8 commit bd7a0a8

File tree

10 files changed

+48
-14
lines changed

10 files changed

+48
-14
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ vendor
33
nbproject/*
44
.idea
55
composer.lock
6-
build
6+
build
7+
_notes

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:37:"PHPUnit\Runner\DefaultTestResultCache":4172:{a:2:{s:7:"defects";a:29:{s:41:"MailerLiteApi\Tests\BatchTest::send_batch";i:4;s:50:"MailerLiteApi\Tests\CampaignsTest::create_campaign";i:4;s:48:"MailerLiteApi\Tests\CampaignsTest::get_campaigns";i:3;s:49:"MailerLiteApi\Tests\FieldsTest::check_fields_data";i:4;s:44:"MailerLiteApi\Tests\FieldsTest::create_field";i:4;s:49:"MailerLiteApi\Tests\GroupsTest::check_groups_data";i:4;s:55:"MailerLiteApi\Tests\GroupsTest::check_single_group_data";i:4;s:60:"MailerLiteApi\Tests\GroupsTest::check_group_subscribers_data";i:4;s:73:"MailerLiteApi\Tests\GroupsTest::check_group_subscribers_unsubscribed_data";i:4;s:60:"MailerLiteApi\Tests\GroupsTest::check_groups_data_with_limit";i:4;s:71:"MailerLiteApi\Tests\GroupsTest::check_group_subscribers_data_with_limit";i:4;s:50:"MailerLiteApi\Tests\GroupsTest::check_groups_count";i:4;s:44:"MailerLiteApi\Tests\GroupsTest::create_group";i:4;s:44:"MailerLiteApi\Tests\GroupsTest::update_group";i:4;s:57:"MailerLiteApi\Tests\GroupsTest::add_and_remove_subscriber";i:4;s:50:"MailerLiteApi\Tests\GroupsTest::import_subscribers";i:4;s:46:"MailerLiteApi\Tests\RestClientTest::get_method";i:4;s:61:"MailerLiteApi\Tests\RestClientTest::mailerlite_sdk_user_agent";i:4;s:47:"MailerLiteApi\Tests\RestClientTest::post_method";i:4;s:46:"MailerLiteApi\Tests\RestClientTest::put_method";i:4;s:49:"MailerLiteApi\Tests\RestClientTest::delete_method";i:4;s:46:"MailerLiteApi\Tests\SegmentsTest::get_segments";i:3;s:40:"MailerLiteApi\Tests\StatsTest::get_stats";i:3;s:52:"MailerLiteApi\Tests\StatsTest::get_stats_in_the_past";i:4;s:60:"MailerLiteApi\Tests\SubscribersTest::get_subscriber_by_email";i:4;s:57:"MailerLiteApi\Tests\SubscribersTest::get_subscriber_by_id";i:4;s:54:"MailerLiteApi\Tests\SubscribersTest::update_subscriber";i:4;s:60:"MailerLiteApi\Tests\SubscribersTest::search_for_a_subscriber";i:3;s:7:"Warning";i:6;}s:5:"times";a:34:{s:73:"MailerLiteApi\Tests\BatchTest::at_least_one_request_is_provided_exception";d:0.012;s:76:"MailerLiteApi\Tests\BatchTest::provided_requests_must_be_batch_request_class";d:0.002;s:41:"MailerLiteApi\Tests\BatchTest::send_batch";d:2.054;s:50:"MailerLiteApi\Tests\CampaignsTest::create_campaign";d:0.472;s:48:"MailerLiteApi\Tests\CampaignsTest::get_campaigns";d:0.415;s:49:"MailerLiteApi\Tests\FieldsTest::check_fields_data";d:0.661;s:44:"MailerLiteApi\Tests\FieldsTest::create_field";d:0.499;s:49:"MailerLiteApi\Tests\GroupsTest::check_groups_data";d:2.65;s:55:"MailerLiteApi\Tests\GroupsTest::check_single_group_data";d:2.677;s:60:"MailerLiteApi\Tests\GroupsTest::check_group_subscribers_data";d:2.75;s:73:"MailerLiteApi\Tests\GroupsTest::check_group_subscribers_unsubscribed_data";d:2.447;s:60:"MailerLiteApi\Tests\GroupsTest::check_groups_data_with_limit";d:4.036;s:71:"MailerLiteApi\Tests\GroupsTest::check_group_subscribers_data_with_limit";d:2.214;s:50:"MailerLiteApi\Tests\GroupsTest::check_groups_count";d:2.395;s:44:"MailerLiteApi\Tests\GroupsTest::create_group";d:2.437;s:44:"MailerLiteApi\Tests\GroupsTest::update_group";d:2.472;s:57:"MailerLiteApi\Tests\GroupsTest::add_and_remove_subscriber";d:10.493;s:50:"MailerLiteApi\Tests\GroupsTest::import_subscribers";d:3.695;s:51:"MailerLiteApi\Tests\MailerLiteTest::invalid_api_key";d:0;s:46:"MailerLiteApi\Tests\RestClientTest::get_method";d:0.506;s:61:"MailerLiteApi\Tests\RestClientTest::mailerlite_sdk_user_agent";d:0.464;s:47:"MailerLiteApi\Tests\RestClientTest::post_method";d:0.479;s:46:"MailerLiteApi\Tests\RestClientTest::put_method";d:0.475;s:49:"MailerLiteApi\Tests\RestClientTest::delete_method";d:0.433;s:57:"MailerLiteApi\Tests\RestClientTest::error_internal_server";d:0.429;s:45:"MailerLiteApi\Tests\RestClientTest::error_400";d:0.468;s:46:"MailerLiteApi\Tests\SegmentsTest::get_segments";d:0.242;s:40:"MailerLiteApi\Tests\StatsTest::get_stats";d:0.248;s:52:"MailerLiteApi\Tests\StatsTest::get_stats_in_the_past";d:0.197;s:60:"MailerLiteApi\Tests\SubscribersTest::get_subscriber_by_email";d:0.796;s:57:"MailerLiteApi\Tests\SubscribersTest::get_subscriber_by_id";d:0.86;s:54:"MailerLiteApi\Tests\SubscribersTest::update_subscriber";d:0.891;s:60:"MailerLiteApi\Tests\SubscribersTest::search_for_a_subscriber";d:1.064;s:7:"Warning";d:0.001;}}}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"keywords": ["mailerlite", "sdk", "email", "marketing"],
77
"type": "library",
88
"require": {
9-
"php" : "^7.1",
9+
"php" : "^8.0",
1010
"php-http/client-common": "^2.0",
1111
"php-http/discovery": "^1.7",
1212
"nyholm/psr7": "^1.0",

phpunit.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
<phpunit bootstrap="tests/bootstrap.php"
2-
colors="true"
3-
stopOnFailure="false">
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage/>
44
<testsuites>
55
<testsuite name="client">
66
<directory>tests</directory>
77
</testsuite>
88
</testsuites>
99
<logging>
10-
<log type="tap" target="build/report.tap"/>
11-
<log type="junit" target="build/report.junit.xml"/>
10+
<junit outputFile="build/report.junit.xml"/>
1211
<!-- <log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
1312
<log type="coverage-text" target="build/coverage.txt"/>
1413
<log type="coverage-clover" target="build/logs/clover.xml"/> -->
1514
</logging>
16-
</phpunit>
15+
</phpunit>

phpunit.xml.bak

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<phpunit bootstrap="tests/bootstrap.php"
2+
colors="true"
3+
stopOnFailure="false">
4+
<testsuites>
5+
<testsuite name="client">
6+
<directory>tests</directory>
7+
</testsuite>
8+
</testsuites>
9+
<logging>
10+
<log type="tap" target="build/report.tap"/>
11+
<log type="junit" target="build/report.junit.xml"/>
12+
<!-- <log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
13+
<log type="coverage-text" target="build/coverage.txt"/>
14+
<log type="coverage-clover" target="build/logs/clover.xml"/> -->
15+
</logging>
16+
</phpunit>

tests/BatchTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ public function send_batch()
4646
->setMethod(BatchRequest::METHOD_POST)
4747
->setPath('/api/v2/subscribers')
4848
->setBody([
49-
'email' => 'one@batch.com',
49+
'email' => BATCH_TEST_EMAIL1,
5050
]);
5151

5252
$batchTwo = (new BatchRequest())
5353
->setMethod(BatchRequest::METHOD_POST)
5454
->setPath('/api/v2/subscribers')
5555
->setBody([
56-
'email' => 'two@batch.com',
56+
'email' => BATCH_TEST_EMAIL2,
5757
]);
5858

5959
$requests[] = $batchOne;

tests/CampaignsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function create_campaign()
2424
$campaignData = [
2525
'subject' => 'Regular Campaign Subject',
2626
'type' => 'regular',
27-
'groups' => [2984475, 3237221] // TODO: improve this with creating new groups
27+
'groups' => [CAMPAIGNS_TEST_GROUP1, CAMPAIGNS_TEST_GROUP2] // TODO: improve this with creating new groups
2828
];
2929

3030
$campaign = $this->campaignsApi->create($campaignData);

tests/SegmentsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public function get_segments()
2525
{
2626
$segments = $this->segmentsApi->get();
2727

28-
$this->assertContains('Demo segment', (array) $segments->first()->data[0]);
28+
$this->assertContains(SEGMENTS_TEST_NAME1, (array) $segments->first()->data[0]);
2929
}
3030
}

tests/SubscribersTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function update_subscriber()
6767
/** @test **/
6868
public function search_for_a_subscriber()
6969
{
70-
$subscribers = $this->subscribersApi->search('demo@mailerlite.com');
70+
$subscribers = $this->subscribersApi->search(SUBSCRIBERS_TEST_EMAIL1);
7171

7272
$this->assertTrue(count($subscribers) > 0);
7373
}

tests/bootstrap.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
<?php
2+
23
require_once __DIR__ . '/../vendor/autoload.php';
34

4-
define('API_KEY', 'fc7b8c5b32067bcd47cafb5f475d2fe9'); // demo account
5+
// demo account
6+
define('API_KEY', 'fc7b8c5b32067bcd47cafb5f475d2fe9');
7+
define('BATCH_TEST_EMAIL1', 'one@batch.com');
8+
define('BATCH_TEST_EMAIL2', 'two@batch.com');
9+
define('SUBSCRIBERS_TEST_EMAIL1', 'demo@mailerlite.com');
10+
define('CAMPAIGNS_TEST_GROUP1', 2984475);
11+
define('CAMPAIGNS_TEST_GROUP2', 3237221);
12+
define('SEGMENTS_TEST_NAME1', 'Demo segment');
13+
14+
// other account (other devs) (adapt below as required)
15+
// define('API_KEY', 'XXX');
16+
// define('BATCH_TEST_EMAIL1', 'email.one@example.com');
17+
// define('BATCH_TEST_EMAIL2', 'email.two@example.com');
18+
// define('SUBSCRIBERS_TEST_EMAIL1', 'subscriber.one@example.com');
19+
// define('CAMPAIGNS_TEST_GROUP1', 000000000);
20+
// define('CAMPAIGNS_TEST_GROUP2', 000000000);
21+
// define('SEGMENTS_TEST_NAME1', 'SDK Test');

0 commit comments

Comments
 (0)