Skip to content

Commit b18a5fb

Browse files
committed
Tests enhanced
1 parent 6460ad5 commit b18a5fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+256
-258
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"homepage": "http://msls.co",
77
"require": {
88
"php": ">=7.4",
9-
"composer/installers": "~1.12.0"
9+
"composer/installers": "~1.12.0",
10+
"ext-json": "*"
1011
},
1112
"require-dev": {
1213
"phpunit/phpunit": "~9.6",
@@ -34,6 +35,7 @@
3435
"analyze": "vendor/bin/phpstan analyze",
3536
"php74": "phpcs -p ./*.php includes/ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 7.4",
3637
"php81": "phpcs -p ./*.php includes/ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.1",
38+
"php82": "phpcs -p ./*.php includes/ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.2",
3739
"prepare": "wget -O build/translations.json http://api.wordpress.org/translations/core/1.0/",
3840
"flags-png": "php bin/flags-png.php > flags/flags.php",
3941
"flags-svg": "php bin/flags-svg.php > css/flags.php"

includes/MslsAdmin.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
/**
1212
* Administration of the options
1313
*
14+
* @method activate_autocomplete(): void
15+
* @method sort_by_description(): void
16+
* @method exclude_current_blog(): void
17+
* @method only_with_translation(): void
18+
* @method output_current_blog(): void
19+
* @method before_output(): void
20+
* @method after_output(): void
21+
* @method before_item(): void
22+
* @method after_item(): void
23+
* @method content_filter(): void
24+
*
1425
* @package Msls
1526
*/
1627
class MslsAdmin extends MslsMain {

includes/MslsBlog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MslsBlog {
3131
/**
3232
* Constructor
3333
*
34-
* @param \StdClass $obj
34+
* @param ?\StdClass $obj
3535
* @param string $description
3636
*/
3737
public function __construct( $obj, $description ) {

includes/MslsJson.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ class MslsJson {
1818
* Container
1919
* @var array
2020
*/
21-
protected $arr = [];
21+
protected array $arr = [];
2222

23-
/**
23+
/** MslsLanguageArray
2424
* Adds a value label pair to the internal class container
2525
*
26-
* @param int $value
26+
* @param ?int $value
2727
* @param string $label
2828
*
2929
* @return MslsJson
3030
*/
31-
public function add( $value, $label ) {
31+
public function add( ?int $value, string $label ) {
3232
$this->arr[] = [
3333
'value' => intval( $value ),
3434
'label' => strval( $label ),

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" backupGlobals="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
33
<coverage>
44
<include>
55
<directory suffix=".php">./includes/</directory>

tests/Component/Icon/TestIconPng.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3-
namespace lloc\Msls\Component\Icon\MslsTests;
3+
namespace lloc\MslsTests\Component\Icon;
44

55
use Brain\Monkey\Functions;
6-
use lloc\MslsTests\Msls_UnitTestCase;
6+
use lloc\MslsTests\MslsUnitTestCase;
77
use lloc\Msls\Component\Icon\IconPng;
88

9-
class TestIconPng extends Msls_UnitTestCase {
9+
class TestIconPng extends MslsUnitTestCase {
1010

11-
public function test_get() {
11+
public function test_get(): void {
1212
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 3 ) . '/' );
1313

1414
$obj = new IconPng();

tests/Component/Icon/TestIconSvg.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?php
22

3-
namespace lloc\Msls\Component\Icon\MslsTests;
3+
namespace lloc\MslsTests\Component\Icon;
44

55
use Brain\Monkey\Functions;
6-
use lloc\MslsTests\Msls_UnitTestCase;
6+
use lloc\MslsTests\MslsUnitTestCase;
77
use lloc\Msls\Component\Icon\IconSvg;
88

9-
class TestIconSvg extends Msls_UnitTestCase {
9+
class TestIconSvg extends MslsUnitTestCase {
1010

11-
public function test_get() {
11+
12+
public function test_get(): void {
1213
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 3 ) . '/' );
1314

1415
$obj = new IconSvg();

tests/Map/TestHrefLang.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<?php
22

3-
namespace lloc\Map\MslsTests;
3+
namespace lloc\MslsTests\Map;
44

55
use Brain\Monkey\Functions;
66
use Brain\Monkey\Filters;
77

8-
use lloc\MslsTests\Msls_UnitTestCase;
8+
use lloc\MslsTests\MslsUnitTestCase;
99
use lloc\Msls\Map\HrefLang;
1010
use lloc\Msls\MslsBlog;
1111
use lloc\Msls\MslsBlogCollection;
1212

13-
class TestHrefLang extends Msls_UnitTestCase {
13+
class TestHrefLang extends MslsUnitTestCase {
14+
15+
protected function setUp(): void {
16+
parent::setUp();
1417

15-
public function get_sut() {
1618
$map = [
1719
'de_DE' => 'de',
1820
'de_DE_formal' => 'de',
@@ -36,28 +38,24 @@ public function get_sut() {
3638
$collection = \Mockery::mock( MslsBlogCollection::class );
3739
$collection->shouldReceive( 'get_objects' )->andReturn( $blogs );
3840

39-
return new HrefLang( $collection );
41+
$this->test = new HrefLang( $collection );
4042
}
4143

42-
public function test_get() {
43-
$obj = $this->get_sut();
44-
45-
$this->assertEquals( 'de-DE', $obj->get( 'de_DE' ) );
46-
$this->assertEquals( 'de-DE', $obj->get( 'de_DE_formal' ) );
47-
$this->assertEquals( 'fr', $obj->get( 'fr_FR' ) );
48-
$this->assertEquals( 'es', $obj->get( 'es_ES' ) );
49-
$this->assertEquals( 'cat', $obj->get( 'cat' ) );
50-
$this->assertEquals( 'en-GB', $obj->get( 'en_GB' ) );
51-
$this->assertEquals( 'en-US', $obj->get( 'en_US' ) );
44+
public function test_get(): void {
45+
$this->assertEquals( 'de-DE', $this->test->get( 'de_DE' ) );
46+
$this->assertEquals( 'de-DE', $this->test->get( 'de_DE_formal' ) );
47+
$this->assertEquals( 'fr', $this->test->get( 'fr_FR' ) );
48+
$this->assertEquals( 'es', $this->test->get( 'es_ES' ) );
49+
$this->assertEquals( 'cat', $this->test->get( 'cat' ) );
50+
$this->assertEquals( 'en-GB', $this->test->get( 'en_GB' ) );
51+
$this->assertEquals( 'en-US', $this->test->get( 'en_US' ) );
5252
}
5353

54-
public function test_get_has_filter() {
55-
$obj = $this->get_sut();
56-
54+
public function test_get_has_filter(): void {
5755
Functions\when( 'has_filter' )->justReturn( true );
5856
Filters\expectApplied('msls_head_hreflang')->once()->with( 'en_US')->andReturn( 'en-US' );
5957

60-
$this->assertEquals( 'en-US', $obj->get( 'en_US' ) );
58+
$this->assertEquals( 'en-US', $this->test->get( 'en_US' ) );
6159
}
6260

6361
}

tests/bootstrap.php renamed to tests/MslsUnitTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Brain\Monkey;
77
use Brain\Monkey\Functions;
88

9-
class Msls_UnitTestCase extends TestCase {
9+
class MslsUnitTestCase extends TestCase {
1010

1111
/**
1212
* Instance of the class to test

0 commit comments

Comments
 (0)