Skip to content

Updated for PHP 8. Tested most with Unit Tests. #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ vendor
nbproject/*
.idea
composer.lock
build
build
.phpunit.result.cache

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file itself should be deleted from the repo too

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"keywords": ["mailerlite", "sdk", "email", "marketing"],
"type": "library",
"require": {
"php" : "^7.1",
"php" : "^7.1 || ^8.0",
"php-http/client-common": "^2.0",
"php-http/discovery": "^1.7",
"nyholm/psr7": "^1.0",
Expand Down
11 changes: 5 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<phpunit bootstrap="tests/bootstrap.php"
colors="true"
stopOnFailure="false">
<?xml version="1.0"?>
<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">
<coverage/>
<testsuites>
<testsuite name="client">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<junit outputFile="build/report.junit.xml"/>
<!-- <log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/> -->
</logging>
</phpunit>
</phpunit>
16 changes: 16 additions & 0 deletions phpunit.xml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<phpunit bootstrap="tests/bootstrap.php"
colors="true"
stopOnFailure="false">
<testsuites>
<testsuite name="client">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<!-- <log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/> -->
</logging>
</phpunit>
4 changes: 2 additions & 2 deletions tests/BatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public function send_batch()
->setMethod(BatchRequest::METHOD_POST)
->setPath('/api/v2/subscribers')
->setBody([
'email' => 'one@batch.com',
'email' => BATCH_TEST_EMAIL1,
]);

$batchTwo = (new BatchRequest())
->setMethod(BatchRequest::METHOD_POST)
->setPath('/api/v2/subscribers')
->setBody([
'email' => 'two@batch.com',
'email' => BATCH_TEST_EMAIL2,
]);

$requests[] = $batchOne;
Expand Down
2 changes: 1 addition & 1 deletion tests/CampaignsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function create_campaign()
$campaignData = [
'subject' => 'Regular Campaign Subject',
'type' => 'regular',
'groups' => [2984475, 3237221] // TODO: improve this with creating new groups
'groups' => [CAMPAIGNS_TEST_GROUP1, CAMPAIGNS_TEST_GROUP2] // TODO: improve this with creating new groups
];

$campaign = $this->campaignsApi->create($campaignData);
Expand Down
2 changes: 1 addition & 1 deletion tests/SegmentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function get_segments()
{
$segments = $this->segmentsApi->get();

$this->assertContains('Demo segment', (array) $segments->first()->data[0]);
$this->assertContains(SEGMENTS_TEST_NAME1, (array) $segments->first()->data[0]);
}
}
2 changes: 1 addition & 1 deletion tests/SubscribersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function update_subscriber()
/** @test **/
public function search_for_a_subscriber()
{
$subscribers = $this->subscribersApi->search('demo@mailerlite.com');
$subscribers = $this->subscribersApi->search(SUBSCRIBERS_TEST_EMAIL1);

$this->assertTrue(count($subscribers) > 0);
}
Expand Down
19 changes: 18 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

define('API_KEY', 'fc7b8c5b32067bcd47cafb5f475d2fe9'); // demo account
// demo account
define('API_KEY', 'fc7b8c5b32067bcd47cafb5f475d2fe9');
define('BATCH_TEST_EMAIL1', 'one@batch.com');
define('BATCH_TEST_EMAIL2', 'two@batch.com');
define('SUBSCRIBERS_TEST_EMAIL1', 'demo@mailerlite.com');
define('CAMPAIGNS_TEST_GROUP1', 2984475);
define('CAMPAIGNS_TEST_GROUP2', 3237221);
define('SEGMENTS_TEST_NAME1', 'Demo segment');

// other account (other devs) (adapt below as required)
// define('API_KEY', 'XXX');
// define('BATCH_TEST_EMAIL1', 'email.one@example.com');
// define('BATCH_TEST_EMAIL2', 'email.two@example.com');
// define('SUBSCRIBERS_TEST_EMAIL1', 'subscriber.one@example.com');
// define('CAMPAIGNS_TEST_GROUP1', 000000000);
// define('CAMPAIGNS_TEST_GROUP2', 000000000);
// define('SEGMENTS_TEST_NAME1', 'SDK Test');