1 | <?php |
||
10 | class MultiDomainTest extends SapphireTest |
||
11 | { |
||
12 | /** |
||
13 | * Set up some test domain configuration |
||
14 | * |
||
15 | * {@inheritDoc} |
||
16 | */ |
||
17 | public function setUp() |
||
34 | |||
35 | /** |
||
36 | * Test that a MultiDomainDomain can be returned from the configured domains |
||
37 | */ |
||
38 | public function testGetDomain() |
||
43 | |||
44 | /** |
||
45 | * Test that all domains can be returned, with or without the primary domain |
||
46 | * |
||
47 | * @dataProvider getAllDomainsProvider |
||
48 | * @param bool $withPrimary |
||
49 | */ |
||
50 | public function testGetAllDomains($withPrimary) |
||
59 | |||
60 | /** |
||
61 | * @return array[] |
||
62 | */ |
||
63 | public function getAllDomainsProvider() |
||
70 | |||
71 | /** |
||
72 | * Test that the primary domain can be returned |
||
73 | */ |
||
74 | public function testGetPrimaryDomain() |
||
80 | |||
81 | /** |
||
82 | * Test that the correct domain can be returned by a provided URL |
||
83 | */ |
||
84 | public function testDomainForUrl() |
||
90 | |||
91 | /** |
||
92 | * Test that if a URL doesn't match any domain then the primary domain is returned |
||
93 | */ |
||
94 | public function testDomainForUrlDefaultsToPrimaryDomain() |
||
98 | |||
99 | public function tearDown() |
||
104 | } |
||
105 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: