Make WordPress Core


Ignore:
Timestamp:
10/16/2015 09:04:12 PM (10 years ago)
Author:
wonderboymusic
Message:

Unit Tests: one $factory to rule them all, and it shall be static.

Using more than one instance of WP_UnitTest_Factory causes all kinds of craziness, due to out-of-sync internal generator sequences. Since we want to use setUpBeforeClass, we were creating ad hoc instances. To avoid that, we were injecting one static instance via Dependency Injection in wpSetUpBeforeClass. All tests should really use the static instance, so we will remove the instance prop $factory.

Replace $this->factory with self::$factory over 2000 times.
Rewrite all of the tests that were hard-coding dynamic values.

#YOLOFriday

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/date/query.php

    r35091 r35225  
    976976     */
    977977    public function test_validate_date_values_should_process_array_value_for_year() {
    978         $p1 = $this->factory->post->create( array( 'post_date' => '2015-01-12 00:00:00' ) );
    979         $p2 = $this->factory->post->create( array( 'post_date' => '2013-01-12 00:00:00' ) );
     978        $p1 = self::$factory->post->create( array( 'post_date' => '2015-01-12 00:00:00' ) );
     979        $p2 = self::$factory->post->create( array( 'post_date' => '2013-01-12 00:00:00' ) );
    980980
    981981        $q = new WP_Query( array(
     
    996996     */
    997997    public function test_validate_date_values_should_process_array_value_for_day() {
    998         $p1 = $this->factory->post->create( array( 'post_date' => '2015-01-12 00:00:00' ) );
    999         $p2 = $this->factory->post->create( array( 'post_date' => '2015-01-10 00:00:00' ) );
     998        $p1 = self::$factory->post->create( array( 'post_date' => '2015-01-12 00:00:00' ) );
     999        $p2 = self::$factory->post->create( array( 'post_date' => '2015-01-10 00:00:00' ) );
    10001000
    10011001        $q = new WP_Query( array(
     
    10171017     */
    10181018    public function test_validate_date_values_should_process_array_value_for_day_when_values_are_invalid() {
    1019         $p1 = $this->factory->post->create( array( 'post_date' => '2015-01-12 00:00:00' ) );
    1020         $p2 = $this->factory->post->create( array( 'post_date' => '2015-01-10 00:00:00' ) );
     1019        $p1 = self::$factory->post->create( array( 'post_date' => '2015-01-12 00:00:00' ) );
     1020        $p2 = self::$factory->post->create( array( 'post_date' => '2015-01-10 00:00:00' ) );
    10211021
    10221022        $q = new WP_Query( array(
Note: See TracChangeset for help on using the changeset viewer.