Skip to content
This repository was archived by the owner on Jun 15, 2022. It is now read-only.

Commit 55d94df

Browse files
committed
Add a factory for generating customers
1 parent 0c0cfb9 commit 55d94df

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* Unit test factory for customers.
5+
*
6+
* Note: The below @method notations are defined solely for the benefit of IDEs,
7+
* as a way to indicate expected return values from the given factory methods.
8+
*
9+
* @method int create( $args = array(), $generation_definitions = null )
10+
* @method WP_User create_and_get( $args = array(), $generation_definitions = null )
11+
* @method int[] create_many( $count, $args = array(), $generation_definitions = null )
12+
*/
13+
class WP_UnitTest_Factory_For_Customer extends WP_UnitTest_Factory_For_User {
14+
15+
function __construct( $factory = null ) {
16+
parent::__construct( $factory );
17+
$this->default_generation_definitions = array(
18+
'user_login' => new WP_UnitTest_Generator_Sequence( 'Customer %s' ),
19+
'user_pass' => 'password',
20+
'user_email' => new WP_UnitTest_Generator_Sequence( 'customer_%[email protected]' ),
21+
);
22+
}
23+
24+
function get_object_by_id( $user_id ) {
25+
return new WC_Customer( $user_id );
26+
}
27+
}

tests/testcase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ protected static function factory() {
2020
$instance = new WP_UnitTest_Factory();
2121

2222
// Add additional factories.
23+
$instance->customer = new WP_UnitTest_Factory_For_Customer( $instance );
2324
$instance->order = new WP_UnitTest_Factory_For_Order( $instance );
2425
$instance->product = new WP_UnitTest_Factory_For_Product( $instance );
2526

0 commit comments

Comments
 (0)