Skip to content
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
7 changes: 5 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ jobs:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: 'The daily API library tests against mautic/mautic have failed. Most likely a PR was merged recently which introduced a regression of some sort.'

cs:
tests:
runs-on: ubuntu-20.04
name: CS tests
name: CS & PHPSTAN tests

steps:
- uses: actions/checkout@v3
Expand All @@ -169,3 +169,6 @@ jobs:

- name: Run CS tests
run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php -v --dry-run --using-cache=no --show-progress=dots --diff $(git diff -- '*.php' --name-only --diff-filter=ACMRTUXB "HEAD~..HEAD")

- name: Run PHPSTAN tests
run: composer phpstan
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
"kint-php/kint": "^4.1",
"friendsofphp/php-cs-fixer": "~3.12.0",
"phpunit/phpunit": "~9.5.0",
"guzzlehttp/guzzle": "^7.5"
"guzzlehttp/guzzle": "^7.5",
"phpstan/phpstan": "^1.11"
},
"suggest": {
"guzzlehttp/guzzle": "A popular HTTP client that implements psr/http-client-implementation."
},
"scripts": {
"test": "vendor/bin/phpunit"
"test": "vendor/bin/phpunit",
"phpstan": "vendor/bin/phpstan analyse"
},
"config": {
"allow-plugins": {
Expand Down
2 changes: 1 addition & 1 deletion lib/MauticApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function getContext($apiContext, AuthInterface $auth, $baseUrl = '

$apiContext = ucfirst($apiContext);

if (!isset($context[$apiContext])) {
if (!isset($contexts[$apiContext])) {
$class = 'Mautic\\Api\\'.$apiContext;

if (!class_exists($class)) {
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 1
paths:
- lib
- tests
6 changes: 3 additions & 3 deletions tests/Api/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function testGetListOfSpecificIds()
public function testCreateWithLocalFileGetAndDelete()
{
// Upload a testing file
$this->apiFiles = $this->getContext('files');
$this->apiFiles->setFolder($this->mediaFolder);
$apiFiles = $this->getContext('files');
$apiFiles->setFolder($this->mediaFolder);
$fileRequest = [
'file' => dirname(__DIR__).'/mauticlogo.png',
];
$response = $this->apiFiles->create($fileRequest);
$response = $apiFiles->create($fileRequest);
$this->assertErrors($response);
$file = $response['file'];

Expand Down
2 changes: 1 addition & 1 deletion tests/Api/CampaignsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public function testCampaignContactEditEvent()
$date = new \DateTime($log['triggerDate'], new \DateTimeZone('UTC'));
$this->assertEquals($log['triggerDate'], $date->format('c'));
} else {
$this->assertFalse(false, 'Event ID not recognized in the log.', var_export($event, true));
$this->fail('Event ID not recognized in the log.'.var_export($event, true));
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Api/FormsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,15 @@ public function testFormSubmissions()
$response = $this->api->getSubmissions($formId);
$this->assertErrors($response);

$submissions = $response['submissions'];
$this->assertTrue(count($submissions) > 0, 'Expected at least one form submission');

foreach ($response['submissions'] as $submission) {
$this->assertSubmission($submission, $formId);
}

$submission = end($submissions);

// Try to fetch the last submission
$response = $this->api->getSubmission($formId, $submission['id']);
$this->assertErrors($response);
Expand Down
8 changes: 6 additions & 2 deletions tests/Api/UtmTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testAddCheckActiveDateAndDelete()
$utmIds = $this->addUtmTags();

// check the date; Should be empty
$this->assertTrue(empty($response[$this->api->itemName()]['lastActive']));
$this->assertTrue(empty($utmIds[$this->api->itemName()]['lastActive']));

// Now add the payload with a known date
$this->testPayload['lastActive'] = '2017-01-17T00:30:08+00:00';
Expand Down Expand Up @@ -150,7 +150,11 @@ protected function removeUtmTags($utmIds)
}
}

$this->assertSame(0, count($response[$this->api->itemName()]['utmtags']), 'Should be no more items');
if (!empty($response)) {
$this->assertSame(0, count($response[$this->api->itemName()]['utmtags']), 'Should be no more items');
} else {
$this->fail('Expected a response object');
}
}

protected function addUtmTags()
Expand Down