Skip to content

Commit

Permalink
Make testing work on recent PHP versions
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Dec 11, 2024
1 parent b5b26dd commit bdc4a20
Show file tree
Hide file tree
Showing 20 changed files with 187 additions and 105 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Code Quality Checks

on:
pull_request:
push:
branches:
- main
- master

jobs:
code-quality:
uses: brightnucleus/.github/.github/workflows/reusable-code-quality.yml@main
15 changes: 15 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Testing

on:
pull_request:
push:
branches:
- main
schedule:
- cron: '17 1 * * *' # Run every day on a seemly random time.

jobs:
test:
uses: brightnucleus/.github/.github/workflows/reusable-testing.yml@main
with:
minimum-php: '7.4'
26 changes: 21 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"phpunit/phpunit": "~5",
"squizlabs/php_codesniffer": "~2.5"
"malukenho/docheader": "^1",
"yoast/phpunit-polyfills": "^3",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5 || ^10",
"squizlabs/php_codesniffer": "^3"
},
"license": "MIT",
"authors": [
Expand All @@ -15,10 +17,11 @@
}
],
"require": {
"php": ">=7.4",
"brightnucleus/exceptions": ">=0.2",
"brightnucleus/config": ">=0.4",
"doctrine/collections": "^1.3",
"symfony/finder": "^3.1"
"doctrine/collections": ">=1.3",
"symfony/finder": ">=3.1"
},
"autoload": {
"psr-4": {
Expand All @@ -27,7 +30,20 @@
},
"autoload-dev": {
"psr-4": {
"BrightNucleus\\View\\Tests\\": "tests/fixtures/classes/"
"BrightNucleus\\View\\Tests\\Fixtures\\": "tests/fixtures/classes/",
"BrightNucleus\\View\\Tests\\": "tests/"
}
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"upload-coverage": "vendor/bin/coveralls -v --coverage_clover clover.xml",
"cs-check": "vendor/bin/phpcs -ps --colors",
"cs-fix": "vendor/bin/phpcbf -ps --colors",
"test": "vendor/bin/phpunit --colors",
"test-coverage": "vendor/bin/phpunit --colors --coverage-clover clover.xml",
"license-check": "vendor/bin/docheader --ansi check src/"
}
}
9 changes: 9 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<ruleset name="Bright Nucleus View">
<description>The coding standard for the Bright Nucleus View package.</description>

<file>src</file>
<file>tests</file>

<rule ref="PSR2"/>
</ruleset>
41 changes: 17 additions & 24 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestSize="true"
beStrictAboutChangesToGlobalState="false">
<testsuites>
<testsuite name="view">
<file>tests/ViewTest.php</file>
<file>tests/ViewBuilderTest.php</file>
<file>tests/ViewFacadeTest.php</file>
</testsuite>
<testsuite name="location">
<file>tests/FilesystemLocationTest.php</file>
<file>tests/LocationCollectionTest.php</file>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php"
verbose="true"
colors="true">
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
4 changes: 3 additions & 1 deletion src/View/Engine/NullEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public function canHandle($criterion): bool
*/
public function getRenderCallback(string $uri, array $context = []): callable
{
return function () { return ''; };
return function () {
return '';
};
}
}
6 changes: 3 additions & 3 deletions src/View/Location/FilesystemLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ protected function getNamePattern(array $criteria, string $extension): string
$extension = ltrim($extension, '.');

if ($uriExtension === $extension) {
$criterion = substr($criterion,0,-strlen(".{$extension}"));
$criterion = substr($criterion, 0, -strlen(".{$extension}"));
}
} else {
$extension = URIHelper::containsExtension($criterion);
if (!empty($extension)) {
$criterion = substr($criterion,0,-strlen(".{$extension}"));
$criterion = substr($criterion, 0, -strlen(".{$extension}"));
}
}

Expand Down Expand Up @@ -164,7 +164,7 @@ protected function getPathPattern(string $relativePath): string
return $this->path;
}

return rtrim($this->path,'/') . '/' . ltrim($relativePath, '/');
return rtrim($this->path, '/') . '/' . ltrim($relativePath, '/');
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/View/Location/Locations.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public function add($location): bool
return false;
}

return parent::add($location);
parent::add($location);

return true;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/View/Support/Findables.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ class Findables extends ArrayCollection
{

}

28 changes: 14 additions & 14 deletions src/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
interface View extends Findable
{

const MERGE = 'merge';
const REPLACE = 'replace';
const ADD_ONLY = 'add-only';
const REPLACE_ONLY = 'replace-only';
const MERGE_ONLY = 'merge-only';
const MERGE = 'merge';
const REPLACE = 'replace';
const ADD_ONLY = 'add-only';
const REPLACE_ONLY = 'replace-only';
const MERGE_ONLY = 'merge-only';

/**
* Check whether the Findable can handle an individual criterion.
Expand Down Expand Up @@ -74,15 +74,15 @@ public function section(string $view, array $context = [], $type = null): string
*/
public function getContext(): array;

/**
* Add information to the context.
*
* @param string $key Context key to add.
* @param mixed $value Value to add under the given key.
* @param string $behavior Behavior to use for adapting the context.
* @return View
*/
public function addToContext( string $key, $value, string $behavior ): View;
/**
* Add information to the context.
*
* @param string $key Context key to add.
* @param mixed $value Value to add under the given key.
* @param string $behavior Behavior to use for adapting the context.
* @return View
*/
public function addToContext(string $key, $value, string $behavior): View;

/**
* Associate a view builder with this view.
Expand Down
9 changes: 5 additions & 4 deletions src/View/View/AbstractView.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ public function getContext(): array
* @param string $behavior Behavior to use for adapting the context.
* @return View
*/
public function addToContext( string $key, $value, string $behavior ): View
public function addToContext(string $key, $value, string $behavior): View
{
switch ($behavior) {
case View::REPLACE:
$this->_context_[$key] = $value;
return $this;
case View::MERGE:
if(array_key_exists($key, $this->_context_)) {
if (array_key_exists($key, $this->_context_)) {
$this->_context_ = array_merge_recursive($this->_context_, [$key => $value]);
return $this;
}
Expand Down Expand Up @@ -247,8 +247,9 @@ protected function assimilateContext(array $context = [])
* @param array $arguments Array of arguments that were used.
* @return mixed Return value of the invokable object.
*/
public function __call($method, $arguments) {
if ( ! property_exists($this, $method)
public function __call($method, $arguments)
{
if (! property_exists($this, $method)
|| ! is_callable($this->$method)) {
trigger_error(
"Call to undefined method {$method} on a view.",
Expand Down
3 changes: 2 additions & 1 deletion src/View/View/NullView.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public function getContext(): array
* @param string $behavior Behavior to use for adapting the context.
* @return View
*/
public function addToContext( string $key, $value, string $behavior ): View {
public function addToContext(string $key, $value, string $behavior): View
{
return $this;
}

Expand Down
6 changes: 3 additions & 3 deletions src/View/ViewBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function getView(string $uri, Engine $engine, $type = null): View
{
if (null === $type) {
$view = $this->getViewFinder()->find([$uri], $engine);
return $view->setBuilder( $this );
return $view->setBuilder($this);
}

return $this->resolveType($type, $uri, $engine);
Expand Down Expand Up @@ -212,7 +212,7 @@ public function addLocation(Location $location)
{
$this->locations->add($location);

unset( $this->viewPathCache );
unset($this->viewPathCache);
$this->viewPathCache = [];

return $this;
Expand Down Expand Up @@ -327,7 +327,7 @@ protected function resolveType($type, string $uri, Engine $engine = null): View
*/
protected function getConfig($config = []): ConfigInterface
{
$defaults = ConfigFactory::create(dirname(__DIR__, 2) . '/config/defaults.php', $config);
$defaults = ConfigFactory::create(dirname(__DIR__, 2) . '/config/defaults.php');
$config = $config
? ConfigFactory::createFromArray(array_merge_recursive($defaults->getArrayCopy(), $config->getArrayCopy()))
: $defaults;
Expand Down
5 changes: 3 additions & 2 deletions tests/FilesystemLocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
* @copyright 2016-2017 Alain Schlesser, Bright Nucleus
*/

namespace BrightNucleus\View;
namespace BrightNucleus\View\Tests;

use BrightNucleus\View\Location\FilesystemLocation;
use BrightNucleus\View\Location\URIs;
use BrightNucleus\View\Tests\TestCase;

/**
* Class FilesystemLocationTest.
Expand All @@ -22,7 +23,7 @@
* @package BrightNucleus\View
* @author Alain Schlesser <[email protected]>
*/
class FilesystemLocationTest extends \PHPUnit_Framework_TestCase
class FilesystemLocationTest extends TestCase
{

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/LocationCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
* @copyright 2016-2017 Alain Schlesser, Bright Nucleus
*/

namespace BrightNucleus\View;
namespace BrightNucleus\View\Tests;

use BrightNucleus\View\Location\FilesystemLocation;
use BrightNucleus\View\Location\Locations;
use BrightNucleus\View\Tests\TestCase;

/**
* Class LocationCollectionTest.
Expand All @@ -22,7 +23,7 @@
* @package BrightNucleus\View
* @author Alain Schlesser <[email protected]>
*/
class LocationCollectionTest extends \PHPUnit_Framework_TestCase
class LocationCollectionTest extends TestCase
{

public function testAddingKnownLocations()
Expand Down
19 changes: 19 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Bright Nucleus Config Component.
*
* @package BrightNucleus\Config
* @author Alain Schlesser <[email protected]>
* @license MIT
* @link http://www.brightnucleus.com/
* @copyright 2016 Alain Schlesser, Bright Nucleus
*/

namespace BrightNucleus\View\Tests;

use Yoast\PHPUnitPolyfills\TestCases\TestCase as PolyfilledTestCase;

class TestCase extends PolyfilledTestCase
{

}
Loading

0 comments on commit bdc4a20

Please sign in to comment.