3
3
namespace Tests \Unit \Api \Customers ;
4
4
5
5
use NathanDunn \Chargebee \Api \Customers \Customer ;
6
+ use Symfony \Component \OptionsResolver \Exception \UndefinedOptionsException ;
6
7
use Tests \Unit \Api \TestCase ;
7
8
8
9
class CustomerTest extends TestCase
@@ -21,6 +22,49 @@ public function should_list_customers()
21
22
$ this ->assertEquals ($ expected , $ customer ->list ());
22
23
}
23
24
25
+ /**
26
+ * @test
27
+ * @dataProvider filters
28
+ */
29
+ public function should_filter_customers ($ filters )
30
+ {
31
+ $ expected = $ this ->getContent (sprintf ('%s/data/responses/customer_list.json ' , __DIR__ ));
32
+
33
+ $ customer = $ this ->getApiMock ();
34
+ $ customer ->expects ($ this ->once ())
35
+ ->method ('get ' )
36
+ ->with ('https://123456789.chargebee.com/api/v2/customers ' , $ filters )
37
+ ->will ($ this ->returnValue ($ expected ));
38
+
39
+ $ this ->assertEquals ($ expected , $ customer ->list ($ filters ));
40
+ }
41
+
42
+ public function filters ()
43
+ {
44
+ return [
45
+ 'email ' => [['email[is] ' => 'test@test.com ' ]],
46
+ 'first name ' => [['first_name[is] ' => 'John ' ]],
47
+ 'last name ' => [['last_name[is] ' => 'Doe ' ]],
48
+ ];
49
+ }
50
+
51
+ /**
52
+ * @test
53
+ */
54
+ public function should_reject_unregistered_filters ()
55
+ {
56
+ $ filters = ['unkown ' => 'field ' ];
57
+
58
+ $ expected = $ this ->getContent (sprintf ('%s/data/responses/customer_list.json ' , __DIR__ ));
59
+
60
+ $ customer = $ this ->getApiMock ();
61
+ $ customer ->expects ($ this ->never ())
62
+ ->method ('get ' );
63
+
64
+ $ this ->expectException (UndefinedOptionsException::class);
65
+ $ customer ->list ($ filters );
66
+ }
67
+
24
68
/** @test */
25
69
public function should_find_customer ()
26
70
{
0 commit comments