Skip to content

Commit 8d4a895

Browse files
committed
Reorganized tests and rewrote test scenarios in consistent form.
1 parent 2d4895f commit 8d4a895

26 files changed

+106
-139
lines changed

test/CapabilitiesTest.php

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,25 @@ public function testSilencedNotice(): void
6666

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

7271
self::assertTrue(true);
7372
}
7473

7574
public function testSilencedWarning(): void
7675
{
77-
$foo = @$bar;
76+
$foo = @$this->triggerWarning();
77+
78+
self::assertTrue(true);
79+
}
80+
81+
public function testWarningDuplicates(): void
82+
{
83+
$this->triggerWarning();
84+
$this->triggerWarning();
85+
$this->triggerWarning();
86+
87+
foreach (1 as $n) {}
7888

7989
self::assertTrue(true);
8090
}
@@ -98,55 +108,18 @@ public function testSilencedDeprecation(): void
98108
self::assertTrue(true);
99109
}
100110

101-
private function triggerWarning(): void
102-
{
103-
foreach (1 as $n) {}
104-
}
105-
106-
public function testDuplicateWarningsA(): void
107-
{
108-
$this->triggerWarning();
109-
110-
self::assertTrue(true);
111-
}
112-
113-
public function testDuplicateWarningsB(): void
114-
{
115-
$this->triggerWarning();
116-
$this->triggerWarning();
117-
$this->triggerWarning();
118-
119-
foreach (1 as $n) {}
120-
121-
self::assertTrue(true);
122-
}
123-
124-
public function testDuplicateWarningsC(): void
125-
{
126-
self::assertTrue(true);
127-
}
128-
129111
public function testMixedSeverities(): void
130112
{
131113
// Notice.
132114
$foo = &self::provideData();
115+
// Warning.
133116
$this->triggerWarning();
134-
// Deprecated.
117+
// Deprecation.
135118
trim(null);
136119

137120
self::assertTrue(true);
138121
}
139122

140-
public function testSilencedWarningNotAffectsStatus(): void
141-
{
142-
@$this->triggerWarning();
143-
144-
// Notice.
145-
$foo = &self::provideData();
146-
147-
self::assertTrue(true);
148-
}
149-
150123
#[DataProvider('provideData')]
151124

152125
public function testDataProvider(): void
@@ -188,4 +161,10 @@ public function testGigaSlow(): void
188161

189162
self::assertTrue(true);
190163
}
164+
165+
private function triggerWarning(): void
166+
{
167+
// foreach() argument must be of type array|object.
168+
foreach (1 as $n) {}
169+
}
191170
}

test/PHPUnit runner.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<?php
2-
chdir(__DIR__ . '/../..');
2+
3+
(function () {
4+
do {
5+
$previousDir = $dir ?? __DIR__;
6+
$dir = dirname($previousDir);
7+
} while (!file_exists("$dir/vendor") && $previousDir !== $dir);
8+
9+
chdir($dir);
10+
})();
311

412
require_once 'vendor/autoload.php';
513

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
An assertion fails.
2+
Tests that when an assertion fails, the test is so marked and the assertion message is printed immediately.
33

44
--ARGS--
55
-c test --colors=always test/CapabilitiesTest.php --filter ::testFailure$
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
An assertion succeeds.
2+
Tests that when an assertion succeeds, the test is so marked.
33

44
--ARGS--
55
-c test --colors=always test/CapabilitiesTest.php --filter ::testSuccess$

test/functional/data provider.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
A successful test is fed two cases by a data provider.
2+
Tests that when a test is fed multiple cases by a data provider, each case is printed with its name and arguments.
33

44
--ARGS--
55
-c test --colors=always test/CapabilitiesTest.php --filter '::testDataProvider\h'

test/functional/diff failure.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
An assertion fails and produces a diff.
2+
Tests that when an assertion fails, a diff is printed immediately.
33

44
--ARGS--
55
-c test --colors=always test/CapabilitiesTest.php --filter ::testDiffFailure$

test/functional/duplicate warnings.phpt

Lines changed: 0 additions & 32 deletions
This file was deleted.

test/functional/deprecation silenced.phpt renamed to test/functional/errors & exceptions/E_DEPRECATED silenced.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
--TEST--
2-
Tests that when a test generates a deprecation that is suppressed, the deprecation is not printed.
2+
Tests that when a test emits a PHP deprecation notice that is suppressed, the test is not marked and the deprecation
3+
message is not printed.
34

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

78
--FILE_EXTERNAL--
8-
../PHPUnit runner.php
9+
../../PHPUnit runner.php
910

1011
--EXPECTF--
1112
PHPUnit %s
@@ -17,5 +18,5 @@ Configuration: %s
1718

1819

1920
Time: %s
20-
%A
21+
2122
OK (1 test, 1 assertion)

test/functional/deprecation.phpt renamed to test/functional/errors & exceptions/E_DEPRECATED.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
--TEST--
2-
A test is marked "deprecated".
2+
Tests that when a test emits a PHP deprecation notice, the test is so marked and the deprecation message is printed.
33

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

77
--FILE_EXTERNAL--
8-
../PHPUnit runner.php
8+
../../PHPUnit runner.php
99

1010
--EXPECTF--
1111
PHPUnit %s
@@ -20,6 +20,6 @@ Deprecated: Serializable@anonymous implements the Serializable interface, which
2020

2121

2222
Time: %s
23-
%A
23+
2424
OK, but %s!
2525
Tests: 1, Assertions: 1, Deprecations: 1.

test/functional/notice silenced.phpt renamed to test/functional/errors & exceptions/E_NOTICE silenced.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
--TEST--
2-
Tests that when a test generates a notice that is suppressed, the notice is not printed.
2+
Tests that when a test emits a PHP notice that is suppressed, the test is not marked and the deprecation message is not
3+
printed.
34

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

78
--FILE_EXTERNAL--
8-
../PHPUnit runner.php
9+
../../PHPUnit runner.php
910

1011
--EXPECTF--
1112
PHPUnit %s
@@ -17,5 +18,5 @@ Configuration: %s
1718

1819

1920
Time: %s
20-
%A
21+
2122
OK (1 test, 1 assertion)

0 commit comments

Comments
 (0)