Skip to content

Commit

Permalink
fixed phpunit10
Browse files Browse the repository at this point in the history
  • Loading branch information
HillLiu committed Feb 23, 2023
1 parent 4f9c5c2 commit 9e378e7
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 77 deletions.
12 changes: 8 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ jobs:
###
command: |
ENABLE_COVERAGE=true
if [ "<< parameters.php-version >>" == "8.1" ] && [ "$ENABLE_COVERAGE" == "true" ]; then
XDEBUG_MODE=coverage phpunit --coverage-clover clover.xml
vendor/bin/phpcs src/
coveralls --coverage_clover=clover.xml -v -o coveralls-upload.json
if [ "<< parameters.php-version >>" == "8.2" ]; then
if [ "$ENABLE_COVERAGE" == "true" ]; then
XDEBUG_MODE=coverage phpunit --coverage-clover clover.xml
vendor/bin/phpcs src/
coveralls --coverage_clover=clover.xml -v -o coveralls-upload.json
else
phpunit --display-deprecations
fi
else
phpunit
fi
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ demo.php
composer.lock
.php_cs.cache
.phpunit.result.cache
.phpunit.cache
clover.xml
.*.sw?
31 changes: 31 additions & 0 deletions phpunit-legacy/phpunit.xml-20230223
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/include.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="false"
processIsolation="false"
stopOnFailure="false"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value="E_ALL" />
<ini name="display_errors" value="true" />
<ini name="display_startup_errors" value="true" />
<env name="APP_ENV" value="testing" />
</php>
</phpunit>
12 changes: 5 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/include.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="false"
processIsolation="false"
stopOnFailure="false"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<coverage processUncoveredFiles="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
Expand Down
67 changes: 34 additions & 33 deletions src/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/
trait Alias
{
public $caller;
public $defaultAlias;
public $parentAlias;
public $preCookFunctionName;
Expand Down Expand Up @@ -71,8 +72,9 @@ public function isCallable($method)
if (!$func) {
if (!empty($this->parentAlias)) {
$parent = $this->parentAlias;
if (spl_object_hash($parent) !== spl_object_hash($caller)
&& is_callable([$parent, 'isCallable'])
if (
spl_object_hash($parent) !== spl_object_hash($caller) &&
is_callable([$parent, 'isCallable'])
) {
$func = $parent->isCallable($method);
}
Expand All @@ -95,16 +97,15 @@ public function __call($method, $args)
$func = $this->isCallable($method);
if (empty($func)) {
return !trigger_error(
'Method not found: "'.
get_class($this).'::'.
$method.'()"'.
'. Please confirm alias file already use lowercase.'
'Method not found: "' .
get_class($this) .
'::' .
$method .
'()"' .
'. Please confirm alias file already use lowercase.'
);
} else {
return call_user_func_array(
$func,
$args
);
return call_user_func_array($func, $args);
}
}

Expand All @@ -116,8 +117,8 @@ public function __call($method, $args)
protected function getTypeOfAlias()
{
return [
'aliasAsKey' => AliasAsKey::getInstance(),
'aliasSrcFile' => AliasSrcFile::getInstance(),
'aliasAsKey' => AliasAsKey::getInstance(),
'aliasSrcFile' => AliasSrcFile::getInstance(),
'aliasAsDefault' => AliasAsDefault::getInstance(),
];
}
Expand Down Expand Up @@ -146,7 +147,7 @@ public function setCallableToAttribute($method, $func)
{
if (isArray($this) && !isset($this[$method])) {
$this[$method] = $func;
} elseif (!isset($this->{$method})) {
} elseif (!isset($this->{$method}) && property_exists($this, $method)){
$this->{$method} = $func;
}
}
Expand Down Expand Up @@ -254,9 +255,9 @@ class AliasAsDefault extends AbstractAlias
public function get($self, $method, $caller)
{
if (isset($self->defaultAlias)) {
$classes = is_array($self->defaultAlias) ?
$self->defaultAlias :
[$self->defaultAlias];
$classes = is_array($self->defaultAlias)
? $self->defaultAlias
: [$self->defaultAlias];
foreach ($classes as $c) {
$func = [$c, $method];
if (is_callable($func)) {
Expand Down Expand Up @@ -300,28 +301,28 @@ public function get($self, $method, $caller)
return false;
}
$path = $this->_getPath($self, $method);
$r = l($path, _INIT_CONFIG, ['ignoreError'=> true]);
$r = l($path, _INIT_CONFIG, ['ignoreError' => true]);
if (!$r) {
return false;
}
$class = importClass($r);
if (!$class) {
return !trigger_error('Not defined default Class. ['.$path.']');
return !trigger_error('Not defined default Class. [' . $path . ']');
} else {
if (!class_exists($class)) {
return !trigger_error('Default class not exists. ['.$class.']');
return !trigger_error(
'Default class not exists. [' . $class . ']'
);
}
$func = new $class($caller);
$func->caller = $caller;
}
if (!is_callable($func)) {
return triggerJson(
'Not implement __invoke function',
[
'path' => $path,
'class' => $class,
'method'=> $method, ]
);
return triggerJson('Not implement __invoke function', [
'path' => $path,
'class' => $class,
'method' => $method,
]);
}
$self->setCallableToAttribute($method, $func);

Expand Down Expand Up @@ -349,9 +350,7 @@ private function _getFileMapping($path, $filter = true)
$fName = basename($fPath);
$fName = $filter(substr($fName, 1, strlen($fName) - 5));
if (empty($fName)) {
return !trigger_error(
'aliasFileFilter not setup correct.'
);
return !trigger_error('aliasFileFilter not setup correct.');
}
$mapArr[$fName] = $fPath;
}
Expand All @@ -369,18 +368,20 @@ private function _getFileMapping($path, $filter = true)
*/
private function _getPath($self, $method)
{
$path = $self->getDir().'src/_';
$path = $self->getDir() . 'src/_';
if ($self->aliasFileFilter) {
if (empty($self->aliasFileMapping)) {
$self->aliasFileMapping
= $this->_getFileMapping($path.'*.php', $self->aliasFileFilter);
$self->aliasFileMapping = $this->_getFileMapping(
$path . '*.php',
$self->aliasFileFilter
);
}
$map = $self->aliasFileMapping;
if (isset($map[$method])) {
return $map[$method];
}
}

return $path.$method;
return $path . $method;
}
}
4 changes: 1 addition & 3 deletions src/Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ function utf8Export($p, $exists = '\PMVC\exists')
{
return $exists('utf8', 'plug')
? plug('utf8')->toUtf8($p)
: (testString($p)
? utf8_encode($p)
: $p);
: $p;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/resources/FakeAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
class FakeAlias extends PlugIn
{
public $foo;

public function init()
{
$this->setDefaultAlias(new FakeObject());
Expand Down Expand Up @@ -60,6 +62,8 @@ public function getDir()
*/
class FakeAliasWithoutArrayAccess
{
public $foo;
public $fake_task;
use Alias;

public function __construct()
Expand Down Expand Up @@ -122,6 +126,6 @@ class FakeInvoke
{
public function __invoke()
{
option('set', 'c', 1);
option('set', 'foo', 1);
}
}
7 changes: 4 additions & 3 deletions tests/resources/src/_fake_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

class _faketask
{
public function __invoke($v = '')
public $caller;
public function __invoke($v = 1)
{
PMVC\option('set', 'd', 1);
PMVC\option('set', 'foo', $v);

return $v;
return $this;
}
}
1 change: 1 addition & 0 deletions tests/resources/src/_without_invoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

class _without_invoke
{
public $caller;
}
6 changes: 4 additions & 2 deletions tests/src/AliasFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public function testAliasFileFilter()
$p = $this->getPlugIn('FakeFileFilterAlias');
$p->setFilter(true);
$expected = 'FakeTask';
$actual = $p->fakeTask($expected);
$p->fakeTask($expected);
$actual = \PMVC\getOption('foo');
$this->assertEquals($expected, $actual);
}

Expand All @@ -34,7 +35,8 @@ public function testAliasCustomFileFilter()
return $name;
});
$expected = 'FakeTask';
$actual = $p->fake__task($expected);
$p->fake__task($expected);
$actual = \PMVC\getOption('foo');
$this->assertEquals($expected, $actual);
}

Expand Down

0 comments on commit 9e378e7

Please sign in to comment.