Skip to content

Commit

Permalink
Merge pull request #58 from ARCANEDEV/php-8-support
Browse files Browse the repository at this point in the history
Adding PHP 8.0 Support and Fixing the tests
  • Loading branch information
arcanedev-maroc authored Nov 30, 2020
2 parents 6231745 + aeead9b commit 84a0405
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 28 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.3, 7.4]
php: [7.3, 7.4, 8.0]
dependency-version: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }}
Expand All @@ -30,9 +30,10 @@ jobs:
php-version: ${{ matrix.php }}
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
coverage: xdebug
tools: composer:v2

- name: Install dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

- name: Execute tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 4
runs: 6
php_code_sniffer:
enabled: true
config:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
"type": "library",
"license": "MIT",
"require": {
"php": "^7.3",
"php": "^7.3|^8.0",
"arcanedev/php-html": "^5.0",
"arcanedev/support": "^8.0"
},
"require-dev": {
"ext-dom": "*",
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.3"
"phpunit/phpunit": "^9.3.3"
},
"autoload": {
"psr-4": {
Expand Down
9 changes: 4 additions & 5 deletions src/Entities/Analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@ protected function renderGoogleScript()
return <<<EOT
<script async src="https://www.googletagmanager.com/gtag/js?id=$this->google"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '$this->google');
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '$this->google');
</script>
EOT;
}
Expand Down
20 changes: 10 additions & 10 deletions tests/Entities/AnalyticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Arcanedev\SeoHelper\Entities\Analytics;
use Arcanedev\SeoHelper\Tests\TestCase;
use Arcanedev\SeoHelper\Tests\Traits\CanAssertsGoogleAnalytics;

/**
* Class AnalyticsTest
Expand All @@ -14,6 +15,13 @@
*/
class AnalyticsTest extends TestCase
{
/* -----------------------------------------------------------------
| Traits
| -----------------------------------------------------------------
*/

use CanAssertsGoogleAnalytics;

/* -----------------------------------------------------------------
| Properties
| -----------------------------------------------------------------
Expand Down Expand Up @@ -72,15 +80,7 @@ public function it_must_render_empty_on_init(): void
/** @test */
public function it_can_render(): void
{
$expectations = [
'<script>',
"ga('create', 'UA-12345678-9', 'auto');",
'</script>',
];

foreach ($expectations as $expected) {
static::assertStringContainsString($expected, $this->analytics->render());
static::assertStringContainsString($expected, (string) $this->analytics);
}
static::assertGoogleAnalytics('UA-12345678-9', $this->analytics->render());
static::assertGoogleAnalytics('UA-12345678-9', (string) $this->analytics);
}
}
18 changes: 10 additions & 8 deletions tests/SeoMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Arcanedev\SeoHelper\Contracts\SeoMeta as SeoMetaContract;
use Arcanedev\SeoHelper\SeoMeta;
use Arcanedev\SeoHelper\Tests\Traits\CanAssertsGoogleAnalytics;

/**
* Class SeoMetaTest
Expand All @@ -14,6 +15,13 @@
*/
class SeoMetaTest extends TestCase
{
/* -----------------------------------------------------------------
| Traits
| -----------------------------------------------------------------
*/

use CanAssertsGoogleAnalytics;

/* -----------------------------------------------------------------
| Properties
| -----------------------------------------------------------------
Expand Down Expand Up @@ -355,17 +363,11 @@ public function it_can_render_add_reset_webmasters(): void
/** @test */
public function it_can_set_and_render_google_analytics(): void
{
static::assertStringContainsString(
"ga('create', 'UA-12345678-9', 'auto');",
$this->seoMeta->render()
);
static::assertGoogleAnalytics('UA-12345678-9', $this->seoMeta->render());

$this->seoMeta->setGoogleAnalytics('UA-98765432-1');

static::assertStringContainsString(
"ga('create', 'UA-98765432-1', 'auto');",
$this->seoMeta->render()
);
static::assertGoogleAnalytics('UA-98765432-1', $this->seoMeta->render());

// Entity
$analyticsEntity = $this->seoMeta->getAnalyticsEntity();
Expand Down
34 changes: 34 additions & 0 deletions tests/Traits/CanAssertsGoogleAnalytics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Arcanedev\SeoHelper\Tests\Traits;

/**
* Trait AssertGoogleAnalytics
*
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
*/
trait CanAssertsGoogleAnalytics
{
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/

/**
* @param string $id
* @param string $actual
*/
public static function assertGoogleAnalytics(string $id, string $actual): void
{
$expectations = [
'<script async src="https://www.googletagmanager.com/gtag/js?id='.$id.'"></script>',
"gtag('config', '{$id}');",
];

foreach ($expectations as $expected) {
static::assertStringContainsString($expected, $actual);
}
}
}

0 comments on commit 84a0405

Please sign in to comment.