Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bridge/rector/FEATURE_PARITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ convert as a documented 🟡 (`RepeatRetryRector` / `RepeatRetryToTestoRector`).
PHPUnit's `markTestIncomplete` moved off this list — it now converts to a Skipped throw with an
`Incomplete: ` reason prefix (`MarkTestIncompleteRector`), a documented lossy 🟡 rather than a ⛔.

PHPUnit assertion methods require a resolved PHPUnit Assert/TestCase declaring class. Custom or
unresolved methods remain manual.

Also done: **declarative skip** — Testo's `#[Skip]` attribute (`testo/skip`) splits the skip rows in
two. A skip that states something about the test rather than about a path through it now converts as
an attribute in every direction: `SkipAttributeToPhpUnitRector` unrolls it into the leading
Expand Down
5 changes: 5 additions & 0 deletions bridge/rector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ memory-leak / retry / repeat, Pest higher-order & `arch()` tests, etc.) are
**not silently dropped**: each is a documented stub rule plus an entry in the direction's
`TODO.md`.

### PHPUnit assertion ownership

Assertion methods must resolve to a declaration on PHPUnit's `Assert` or `TestCase`; keep PHPUnit
resolvable while migrating. An unrelated, overridden, magic or unresolved method is left untouched.

### Argument order (important)

Testo's comparison assertions are `(actual, expected)`; PHPUnit's are `(expected, actual)`.
Expand Down
19 changes: 18 additions & 1 deletion bridge/rector/src/Internal/PhpunitAssertionCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*
* Only a call inside a class counts, which is where a test method or a `static` data provider
* lives; a call in a free function or at namespace level is left alone.
* Method calls must resolve to PHPUnit's Assert/TestCase declaration. An unresolved receiver,
* magic method, trait requirement, or a user declaration with the same name stays untouched.
*
* @internal
*/
Expand Down Expand Up @@ -50,7 +52,22 @@ public function name(Node $node): ?string
return null;
}

return $name;
if ($node instanceof FuncCall) {
return $name;
}

$scope = $node->getAttribute(AttributeKey::SCOPE);
\assert($scope instanceof Scope);
$class = $scope->getClassReflection();
if ($class === null || !$class->hasNativeMethod($name)) {
return null;
}

$method = $class->getNativeMethod($name);
return \in_array($method->getDeclaringClass()->getName(), [
'PHPUnit\\Framework\\Assert',
'PHPUnit\\Framework\\TestCase',
], true) ? $method->getName() : null;
}

private function functionName(FuncCall $call): ?string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class AssertNotTrueNotFalseTest
class AssertNotTrueNotFalseTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -11,7 +11,7 @@ class AssertNotTrueNotFalseTest
-----
<?php

class AssertNotTrueNotFalseTest
class AssertNotTrueNotFalseTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

class CustomFlatAssertions
{
public function assertSame($expected, $actual): string { return 'custom'; }
public function run(): string { return $this->assertSame(1, 2); }
}

class CustomFlatStaticAssertions
{
public static function assertTrue($actual): string { return 'custom'; }
public function run(): string { return self::assertTrue(false); }
}

class MagicFlatAssertions
{
public function __call(string $name, array $arguments): string { return 'magic'; }
public function run(): string { return $this->assertSame(1, 2); }
}

class UnresolvedFlatAssertions extends \MissingTesting\TestCase
{
public function run(): void { $this->assertSame(1, 2); }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -10,7 +10,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
4 changes: 4 additions & 0 deletions bridge/rector/src/PhpunitToTesto/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,7 @@ expectations belong to a test method (or a static data provider); a matching cal
or at namespace level is left untouched. Each rule carries an `outside_method_left_unchanged` fixture
proving the no-op. (Unlike the reverse direction the outputs — static `\Testo\Assert::*`/`\Testo\Expect::*`
calls and `throw` — are valid anywhere, so this is a scoping/consistency choice, not a fatal-avoidance one.)

Assertion methods handled by `AssertCallToTestoRector` and `TypedAssertCallToTestoRector` must
resolve to a native PHPUnit Assert/TestCase declaration. Custom, overridden, magic, mixed-receiver
and unresolved calls are left untouched. Keep PHPUnit resolvable until the migration is complete.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -11,7 +11,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand All @@ -13,7 +13,7 @@ class SomeTest
-----
<?php

class SomeTest
class SomeTest extends \PHPUnit\Framework\TestCase
{
public function test()
{
Expand Down
Loading