Skip to content

Commit

Permalink
Tests: fixes, add php 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jul 10, 2023
1 parent 7ddc091 commit b2bfba8
Show file tree
Hide file tree
Showing 23 changed files with 178 additions and 29 deletions.
8 changes: 3 additions & 5 deletions tests/Cases/CodestyleTest.phpt
Expand Up @@ -2,17 +2,14 @@

namespace Tests\Cases;

use Contributte\Tester\TestCase\BaseTestCase;
use Generator;
use Symfony\Component\Process\Process;
use Tester\Assert;
use Tester\TestCase;

require_once __DIR__ . '/../bootstrap.php';

/**
* @testCase
*/
class CodestyleTest extends BaseTestCase
class CodestyleTest extends TestCase
{

/**
Expand Down Expand Up @@ -79,6 +76,7 @@ class CodestyleTest extends BaseTestCase
yield [__DIR__ . '/../Sets/next/1-good'];
yield [__DIR__ . '/../Sets/php80/1-good'];
yield [__DIR__ . '/../Sets/php81/1-good'];
yield [__DIR__ . '/../Sets/php82/1-good'];
}

public function provideBadSets(): iterable
Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/base/1-good/Foobar.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Base;

final class Foobar implements IFoobar
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/base/1-good/IFoobar.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Base;

interface IFoobar
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/base/1-good/TFoo.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Base;

/**
* @mixin IFoobar
Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/base/2-bad/Foobar.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Base;

use Tests\Fixtures;
use Tests\Fixtures as FixturesAlias;
Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/base/2-bad/IFoobar.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Base;

interface IFoobar
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/base/2-bad/TFoo.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Base;

/**
* @mixin IFoobar
Expand Down
8 changes: 3 additions & 5 deletions tests/Sets/base/2-bad/snapshot.txt
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="3.7.1">
<checkstyle version="%A%">
<file name="Foobar.php">
<error line="5" column="1" severity="error" message="Use Tests\Fixtures is from the same namespace &#x2013; that is prohibited." source="SlevomatCodingStandard.Namespaces.UseFromSameNamespace.UseFromSameNamespace"/>
<error line="46" column="12" severity="error" message="Method \Tests\Foobar::isBaz() does not have native type hint for its parameter $value but it should be possible to add it based on @param annotation &quot;mixed&quot;." source="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<error line="46" column="12" severity="error" message="Method \Tests\Base\Foobar::isBaz() does not have native type hint for its parameter $value but it should be possible to add it based on @param annotation &quot;mixed&quot;." source="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<error line="126" column="9" severity="error" message="Unused variable $class1." source="SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable"/>
<error line="126" column="19" severity="error" message="Class \Tests\Fixtures\DummyClass should not be referenced via a fully qualified name, but via a use statement." source="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName"/>
<error line="128" column="9" severity="error" message="Unused variable $class2." source="SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable"/>
Expand All @@ -11,7 +10,6 @@
<error line="130" column="19" severity="error" message="Partial use statements are not allowed, but referencing FixturesAlias\DummyClass found." source="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.PartialUse"/>
</file>
<file name="TFoo.php">
<error line="12" column="15" severity="error" message="Property \Tests\TFoo::$foobar does not have native type hint for its value but it should be possible to add it based on @var annotation &quot;mixed&quot;." source="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
<error line="12" column="15" severity="error" message="Property \Tests\Base\TFoo::$foobar does not have native type hint for its value but it should be possible to add it based on @var annotation &quot;mixed&quot;." source="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
</file>
</checkstyle>

2 changes: 1 addition & 1 deletion tests/Sets/next/1-good/Foobar.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Next;

use Exception;

Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/next/1-good/IFoobar.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Next;

interface IFoobar
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/next/1-good/TFoo.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Next;

/**
* @mixin IFoobar
Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/php80/1-good/Foobar.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Php80;

use Exception;

Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/php80/1-good/IFoobar.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Php80;

interface IFoobar
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/php80/1-good/TFoo.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Php80;

/**
* @mixin IFoobar
Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/php81/1-good/Foobar.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Php81;

use Exception;

Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/php81/1-good/IFoobar.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Php81;

interface IFoobar
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Sets/php81/1-good/TFoo.php
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);

namespace Tests;
namespace Tests\Php81;

/**
* @mixin IFoobar
Expand Down
116 changes: 116 additions & 0 deletions tests/Sets/php82/1-good/Foobar.php
@@ -0,0 +1,116 @@
<?php declare(strict_types = 1);

namespace Tests\Php82;

use Exception;

final class Foobar implements IFoobar
{

use TFoo;

public const FOO_LENGTH = 5;
public const FOO_BAR = 'foo.bar';
public const FOO_BAZ = [
'first',
'second',
];

/** @inject */
public Foobar $service;

/** @var array<string> */
public array $foo = [];

protected string $bar;

private int $baz;

public function __construct()
{
$this->foo = ['1', '2', '3'];
$this->bar = 'bar';
$this->baz = 0;

$this->getSwitchCase();
}

public function isBaz(mixed $value): bool
{
if (is_bool($value)) {
return true;
}

return $this->baz !== 0;
}

/**
* @return array<string>
*/
public function getArrayFunction(): array
{
return array_map(fn (string $val): string => mb_strtolower($val), $this->getForEach());
}

/**
* Needs implementation
*
* @param array<mixed>|null $baz
*/
public function interfaceMethod(string $foo, int $bar, ?array $baz = null): void
{
throw new Exception('Not yet implemented');
}

/**
* @return array<string>
*/
protected function getForEach(): array
{
$result = [];

foreach ($this->foo as $foo) {
if (strlen($foo) === self::FOO_LENGTH) {
continue;
}

$result[] = $foo;
}

return $result;
}

private function getSwitchCase(): void
{
switch ($this->bar) {
case 'case1':
$this->baz = 1;

break;
case 'case2':
$this->baz = 2;

break;
case 'case3':
throw new Exception('Case 3 error');
default:
$this->baz = 4;
}
}

private function ifElseStatement(): void
{
$this->foobar = 1;

if ($this->bar === 'case1') {
$this->baz = 1;
} elseif ($this->bar === 'case2') {
$this->baz = 2;
} else {
$this->baz = 3;
}

$this->bar = 'case3';
}

}
13 changes: 13 additions & 0 deletions tests/Sets/php82/1-good/IFoobar.php
@@ -0,0 +1,13 @@
<?php declare(strict_types = 1);

namespace Tests\Php82;

interface IFoobar
{

/**
* @param array<mixed>|null $baz
*/
public function interfaceMethod(string $foo, int $bar, ?array $baz = null): void;

}
18 changes: 18 additions & 0 deletions tests/Sets/php82/1-good/TFoo.php
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace Tests\Php82;

/**
* @mixin IFoobar
*/
trait TFoo
{

protected mixed $foobar;

protected function contextFoobar(): void
{
$this->interfaceMethod('foo', 3);
}

}
3 changes: 3 additions & 0 deletions tests/Sets/php82/1-good/codesniffer.files
@@ -0,0 +1,3 @@
tests/Sets/php81/1-good/Foobar.php
tests/Sets/php81/1-good/IFoobar.php
tests/Sets/php81/1-good/TFoo.php
6 changes: 6 additions & 0 deletions tests/Sets/php82/1-good/codesniffer.xml
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<ruleset name="Test ruleset-8.2.xml">
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<rule ref="./../../../../ruleset-8.2.xml"/>
</ruleset>
5 changes: 1 addition & 4 deletions tests/bootstrap.php
Expand Up @@ -7,7 +7,4 @@
exit(1);
}

// Configure environment
Environment::setupTester();
Environment::setupTimezone();
Environment::setupVariables(__DIR__);
Environment::setup(__DIR__);

0 comments on commit b2bfba8

Please sign in to comment.