-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Labels
feature/assertionIssues related to assertions and expectationsIssues related to assertions and expectationstype/enhancementA new idea that should be implementedA new idea that should be implemented
Description
TestCase
is currently 2276 lines long and contains 129 functions, we can argue that this class concentrates too much responsibilities and is a god class. Unfortunately this class extends Assert
which is 2293 lines long and contains 175 functions.
- Any phpunit test must extends the TestCase (thus
Assert
) and inherit from too much logic/functions - It's not possible to remove assertions from userland tests
- Personally and where I work we always use the FQCN for assertions (for example
Assert::assertTrue(...)
) to use composition. Unfortunately to enforce this convention you need to rely on external tools.
- Personally and where I work we always use the FQCN for assertions (for example
- To add new assertions, people often add them is some userland abstract test classes to keep the same syntax
self::assertXxx()
. This bloat classes even more, I saw it many times in the wild. If Assert was not available by default it would help to promote usage of composition over inheritance and create its own "Assert".
My question is: could we remove the Assert
inheritance from TestCase
? What is the advantage of extending Assert
? Writing self::
instead of Assert::
doesn't seem to be a good reason.
Proposal
- Move the assertions in a trait,
AssertTrait
- Remove inheritance of
Assert
inTestCase
but "use"AssertTrait
to not have any BC in the next major - Promote usage of
Assert::
Because there is a trait, it would be easy to have our own Assert
by using use AssertTrait
and add methods.
class MyAssert {
use PhpUnitAssert;
// custom methods...
}
In a future version we could imagine to remove the trait from TestCase
. By doing so, devs would be free to either use AssertTrait
to keep the "legacy" syntax or to use composition (Assert::
).
class MyTest extends TestCase {
use PhpUnitAssert;
// We can use "self::assertXxx()"
}
or
class MyTest extends TestCase {
// We can use "Assert::assertXxx()"
}
kaznovac and MightySepp666
Metadata
Metadata
Assignees
Labels
feature/assertionIssues related to assertions and expectationsIssues related to assertions and expectationstype/enhancementA new idea that should be implementedA new idea that should be implemented