[wp-trac] [WordPress Trac] #33968: Improve performance of Unit Tests for 4.4
WordPress Trac
noreply at wordpress.org
Thu Oct 15 13:02:51 UTC 2015
#33968: Improve performance of Unit Tests for 4.4
------------------------------+-----------------------
Reporter: jorbin | Owner: jorbin
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 4.4
Component: Build/Test Tools | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
------------------------------+-----------------------
Comment (by jdgrimes):
Replying to [comment:54 wonderboymusic]:
> In [changeset:"35186"]:
> {{{
> #!CommitTicketReference repository="" revision="35186"
> Unit Tests: implement `setUpBeforeClass()` and `tearDownAfterClass()` on
`WP_UnitTestCase`. Use late static binding (plus a gross fallback for PHP
5.2) to check if `wpSetUpBeforeClass()` or `wpTearDownAfterClass()` exist
on the called class, and then call it and pass a static
`WP_UnitTest_Factory` instance via Dependency Injection, if it exists.
>
> This makes it way easier to add fixtures, and tear them down, without
needing to instantiate `WP_UnitTest_Factory` in every class - removes the
need to call `commit_transaction()` in each individual class.
>
> See #30017, #33968.
> }}}
Is there any reason why we can't just create one single instance of the
factory and reuse it across all of the tests?
{{{
#!php
// in bootstrap.php
include 'wp-unit-test-case.php';
WP_UnitTestCase::$static_factory = new WP_UnitTest_Factory();
}}}
{{{
#!php
// in WP_UnitTestCase::setUp();
$this->factory = self::$static_factory;
}}}
And there would no longer be any need to create the factory in
`setUpBeforeClass()`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33968#comment:62>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list