Skip to content

Commit

Permalink
Reorganized tests and rewrote test scenarios in consistent form.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Nov 5, 2024
1 parent 2d4895f commit 8d4a895
Show file tree
Hide file tree
Showing 26 changed files with 106 additions and 139 deletions.
63 changes: 21 additions & 42 deletions test/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,25 @@ public function testSilencedNotice(): void

public function testWarning(): void
{
// foreach() argument must be of type array|object.
foreach (1 as $n) {}
$this->triggerWarning();

self::assertTrue(true);
}

public function testSilencedWarning(): void
{
$foo = @$bar;
$foo = @$this->triggerWarning();

self::assertTrue(true);
}

public function testWarningDuplicates(): void
{
$this->triggerWarning();
$this->triggerWarning();
$this->triggerWarning();

foreach (1 as $n) {}

self::assertTrue(true);
}
Expand All @@ -98,55 +108,18 @@ public function testSilencedDeprecation(): void
self::assertTrue(true);
}

private function triggerWarning(): void
{
foreach (1 as $n) {}
}

public function testDuplicateWarningsA(): void
{
$this->triggerWarning();

self::assertTrue(true);
}

public function testDuplicateWarningsB(): void
{
$this->triggerWarning();
$this->triggerWarning();
$this->triggerWarning();

foreach (1 as $n) {}

self::assertTrue(true);
}

public function testDuplicateWarningsC(): void
{
self::assertTrue(true);
}

public function testMixedSeverities(): void
{
// Notice.
$foo = &self::provideData();
// Warning.
$this->triggerWarning();
// Deprecated.
// Deprecation.
trim(null);

self::assertTrue(true);
}

public function testSilencedWarningNotAffectsStatus(): void
{
@$this->triggerWarning();

// Notice.
$foo = &self::provideData();

self::assertTrue(true);
}

#[DataProvider('provideData')]

public function testDataProvider(): void
Expand Down Expand Up @@ -188,4 +161,10 @@ public function testGigaSlow(): void

self::assertTrue(true);
}

private function triggerWarning(): void
{
// foreach() argument must be of type array|object.
foreach (1 as $n) {}
}
}
10 changes: 9 additions & 1 deletion test/PHPUnit runner.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?php
chdir(__DIR__ . '/../..');

(function () {
do {
$previousDir = $dir ?? __DIR__;
$dir = dirname($previousDir);
} while (!file_exists("$dir/vendor") && $previousDir !== $dir);

chdir($dir);
})();

require_once 'vendor/autoload.php';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
An assertion fails.
Tests that when an assertion fails, the test is so marked and the assertion message is printed immediately.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testFailure$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
An assertion succeeds.
Tests that when an assertion succeeds, the test is so marked.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testSuccess$
Expand Down
2 changes: 1 addition & 1 deletion test/functional/data provider.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
A successful test is fed two cases by a data provider.
Tests that when a test is fed multiple cases by a data provider, each case is printed with its name and arguments.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter '::testDataProvider\h'
Expand Down
2 changes: 1 addition & 1 deletion test/functional/diff failure.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
An assertion fails and produces a diff.
Tests that when an assertion fails, a diff is printed immediately.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testDiffFailure$
Expand Down
32 changes: 0 additions & 32 deletions test/functional/duplicate warnings.phpt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
--TEST--
Tests that when a test generates a deprecation that is suppressed, the deprecation is not printed.
Tests that when a test emits a PHP deprecation notice that is suppressed, the test is not marked and the deprecation
message is not printed.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testSilencedDeprecation$

--FILE_EXTERNAL--
../PHPUnit runner.php
../../PHPUnit runner.php

--EXPECTF--
PHPUnit %s
Expand All @@ -17,5 +18,5 @@ Configuration: %s


Time: %s
%A

OK (1 test, 1 assertion)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--TEST--
A test is marked "deprecated".
Tests that when a test emits a PHP deprecation notice, the test is so marked and the deprecation message is printed.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testDeprecation$

--FILE_EXTERNAL--
../PHPUnit runner.php
../../PHPUnit runner.php

--EXPECTF--
PHPUnit %s
Expand All @@ -20,6 +20,6 @@ Deprecated: Serializable@anonymous implements the Serializable interface, which


Time: %s
%A

OK, but %s!
Tests: 1, Assertions: 1, Deprecations: 1.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
--TEST--
Tests that when a test generates a notice that is suppressed, the notice is not printed.
Tests that when a test emits a PHP notice that is suppressed, the test is not marked and the deprecation message is not
printed.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testSilencedNotice$

--FILE_EXTERNAL--
../PHPUnit runner.php
../../PHPUnit runner.php

--EXPECTF--
PHPUnit %s
Expand All @@ -17,5 +18,5 @@ Configuration: %s


Time: %s
%A

OK (1 test, 1 assertion)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--TEST--
A test is marked "notice".
Tests that when a test emits a PHP notice, the test is so marked and the notice message is printed immediately.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testNotice$

--FILE_EXTERNAL--
../PHPUnit runner.php
../../PHPUnit runner.php

--EXPECTF--
PHPUnit %s
Expand All @@ -20,6 +20,6 @@ Notice: Only variables should be assigned by reference in %s%eCapabilitiesTest.p


Time: %s
%A

OK, but %s!
Tests: 1, Assertions: 1, Notices: 1.
27 changes: 27 additions & 0 deletions test/functional/errors & exceptions/E_WARNING duplicates.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Tests that when a test emits a PHP warning multiple times, only unique occurrences are printed.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testWarningDuplicates$

--FILE_EXTERNAL--
../../PHPUnit runner.php

--EXPECTF--
PHPUnit %s

Runtime: %s
Configuration: %s

100% W ScriptFUSIONTest\Pip\CapabilitiesTest::testWarningDuplicates (%d ms)

Warning: foreach() argument must be of type array|object, int given in %s%eCapabilitiesTest.php on line %d

Warning: foreach() argument must be of type array|object, int given in %s%eCapabilitiesTest.php on line %d



Time: %s

OK, but %s!
Tests: 1, Assertions: 1, Warnings: 2.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--TEST--
Tests that when a test generates a warning that is suppressed, the warning is not printed.
Tests that when a test emits a PHP warning that is suppressed, the warning is not printed.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testSilencedWarning$

--FILE_EXTERNAL--
../PHPUnit runner.php
../../PHPUnit runner.php

--EXPECTF--
PHPUnit %s
Expand All @@ -17,5 +17,5 @@ Configuration: %s


Time: %s
%A

OK (1 test, 1 assertion)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--TEST--
A test is marked "warning".
Tests that when a test emits a PHP warning, the test is so marked and the warning message is printed immediately.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testWarning$

--FILE_EXTERNAL--
../PHPUnit runner.php
../../PHPUnit runner.php

--EXPECTF--
PHPUnit %s
Expand All @@ -20,6 +20,6 @@ Warning: foreach() argument must be of type array|object, int given in %s%eCapab


Time: %s
%A

OK, but %s!
Tests: 1, Assertions: 1, Warnings: 1.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
--TEST--
An exception containing another exception is thrown by another class.
Tests that when the SUT throws an exception containing another exception, both exceptions, and their traces, are
printed.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testNestedException$

--FILE_EXTERNAL--
../PHPUnit runner.php
../../PHPUnit runner.php

--EXPECTF--
PHPUnit %s
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--TEST--
An exception is thrown in the test case.
Tests that when a test throws an exception, the test is so marked and the exception type and message are printed.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testException$

--FILE_EXTERNAL--
../PHPUnit runner.php
../../PHPUnit runner.php

--EXPECTF--
PHPUnit %s
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
--TEST--
When a test generates errors with different severities and silences some of them, first non-silenced error determines
overall test status and all non-silenced messages are shown.
Tests that when multiple PHP error types are emitted, the first so emitted determines the test status but all error
messages are printed.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testMixedSeverities$

--FILE_EXTERNAL--
../PHPUnit runner.php
../../PHPUnit runner.php

--EXPECTF--
PHPUnit %s
Expand All @@ -25,6 +25,6 @@ Notice: Only variables should be assigned by reference in %s%eCapabilitiesTest.p


Time: %s
%A

OK, but %s!
Tests: 1, Assertions: 1, Warnings: 1, Deprecations: 1, Notices: 1.
2 changes: 1 addition & 1 deletion test/functional/incomplete.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
A test is marked "incomplete".
Tests that when a test is marked "incomplete", the test is so marked.

--ARGS--
-c test --colors=always test/CapabilitiesTest.php --filter ::testIncomplete$
Expand Down
2 changes: 1 addition & 1 deletion test/functional/multiple files.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Tests that multiple files tested together are counted correctly.
Tests that when multiple files are tested together, they are counted correctly.

--ARGS--
-c test --colors=always test/multi
Expand Down
Loading

0 comments on commit 8d4a895

Please sign in to comment.