Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brianvarskonst committed Jun 5, 2024
1 parent 596a6c6 commit 4fdf926
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

/**
* test case
*/
* test case
*/
namespace BarFail;

use A\B;
Expand All @@ -12,48 +12,48 @@ use Exception;
use \DOMComment;
use Closure as MyClosure;
/**
* Class Foo
*/
* Class Foo
*/
class Foo extends \DOMComment
{
private $a = \DOMDocument::TEST;
private $a = \DOMDocument::TEST;

/**
* method foo
*
* @param A\B $b b
* @param \DOMDocument $d d
* @param \DOMDocument|int|A\B $f f
*
* @throws \Exception
*/
public function foo(A\B $b, \DOMDocument $d, $f)
{
/** @var \Exception $e */
$e = new \Exception('ups!');
throw $e;
}
/**
* method foo
*
* @param A\B $b b
* @param \DOMDocument $d d
* @param \DOMDocument|int|A\B $f f
*
* @throws \Exception
*/
public function foo(A\B $b, \DOMDocument $d, $f)
{
/** @var \Exception $e */
$e = new \Exception('ups!');
throw $e;
}

/**
* returns some awesome \DOMDocument
*
* @throws \BarFail\FooException
*/
public function bar()
{
/** @var A\Be $g */
$g = new A\Be();
throw new \BarFail\FooException();
}
/**
* returns some awesome \DOMDocument
*
* @throws \BarFail\FooException
*/
public function bar()
{
/** @var A\Be $g */
$g = new A\Be();
throw new \BarFail\FooException();
}

/**
* foo
*
* @param \Closure $c
*
* @return void
*/
public function myClosureFoo(\Closure $c)
{
}
/**
* foo
*
* @param \Closure $c
*
* @return void
*/
public function myClosureFoo(\Closure $c)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class UnnecessaryNamespaceUsageUnitTest extends AbstractBrianvarskonstSniffUnitTest
{
protected array $expectedErrorList = [
protected array $expectedWarningList = [
'UnnecessaryNamespaceUsageUnitTest.pass.1.inc' => [],
'UnnecessaryNamespaceUsageUnitTest.pass.2.inc' => [],
'UnnecessaryNamespaceUsageUnitTest.pass.3.inc' => [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@
* @return void
*/
function wfFailedExamples() {
$a = 1;
$a = 1;

$b = 2;
$b = 2;

// Comment
// Comment

// Comment 2
// Comment 2

// Comment 3
// Comment 3

/* Comment 4 */
/* Comment 4 */

# Comment 5
# Comment 5

$c = 3;
$c = 3;
}

/**
* Passed examples.
* @return void
*/
function wfPassedExamples() {
$a = 1;
$a = 1;

$b = 2;
$b = 2;
}
7 changes: 0 additions & 7 deletions Brianvarskonst/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,6 @@
<!-- forbid static:: in final class -->
<rule ref="SlevomatCodingStandard.Classes.UselessLateStaticBinding" />

<rule ref="SlevomatCodingStandard.Whitespaces.DuplicateSpaces">
<type>warning</type>
<properties>
<property name="ignoreSpacesInComment" value="yes" />
</properties>
</rule>

<!-- Rules for recent language features -->
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat" />
<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch" />
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
"cs": "./vendor/bin/phpcs -q --parallel=$(nproc) -s",
"cs:analyze": "./vendor/bin/phpstan --no-progress",
"cs:bf": "php -d error_reporting=24575 vendor/bin/phpcbf;exit 0",
"test:all": "@php ./vendor/bin/phpunit"
"test": [
"@test:unit",
"@test:integration"
],
"test:unit": "@php ./vendor/bin/phpunit",
"test:integration": "@php vendor/bin/phpcs -s --standard=Brianvarskonst integrationtests/testfile.php"
}
}
48 changes: 30 additions & 18 deletions integrationtests/testfile.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Symfony package.
*
* Taken from symfony-docs: contributing/code/standards.rst
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Acme;

const BAM = 1;

/**
* Coding standards demonstration.
*/
// phpcs:ignore Brianvarskonst.Namespace.Psr4.InvalidPSR4, Squiz.Classes.ClassFileName.NoMatch
class FooBar
{
public const SOME_CONST = 42;
public const STR_CONST = '43';
protected const PROTECT = 0;
public const LALA = 'lala';

/**
* @var string
*/
private $fooBar;
private string $fooBar;

/**
* @param string $dummy Some argument description
*/
/** @param string $dummy Some argument description */
public function __construct(string $dummy)
{
$this->fooBar = $this->transformText($dummy);
}

/**
* @return string
*
* @deprecated
*/
/** @deprecated */
public function someDeprecatedMethod(): string
{
@\trigger_error(\sprintf('The %s() method is deprecated since version 2.8 and will be removed in 3.0. Use Acme\Baz::someMethod() instead.', __METHOD__), E_USER_DEPRECATED);
@\trigger_error(
\sprintf(
'The %s() method is deprecated since version 2.8 and will be removed in 3.0. Use %s instead.',
__METHOD__,
'Acme\Baz::someMethod()',
),
E_USER_DEPRECATED,
);

return Baz::someMethod();
}
Expand All @@ -49,7 +61,7 @@ public function someDeprecatedMethod(): string
*
* @throws \RuntimeException When an invalid option is provided
*/
private function transformText($dummy, array $options = []): ?string
private function transformText(bool| string $dummy, array $options = []): ?string
{
/** @var array<string, string> $defaultOptions */
$defaultOptions = [
Expand All @@ -67,15 +79,15 @@ private function transformText($dummy, array $options = []): ?string

$mergedOptions = \array_merge(
$defaultOptions,
$options
$options,
);

if (true === $dummy) {
if ($dummy === true) {
return null;
}

if ('string' === $dummy) {
if ('values' === $mergedOptions['some_default']) {
if ($dummy === 'string') {
if ($mergedOptions['some_default'] === 'values') {
return \substr($dummy, 0, 5);
}

Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="tests/bootstrap.php"
cacheResult="false"
>
Expand Down

0 comments on commit 4fdf926

Please sign in to comment.