1 | <?php |
||
9 | class MultiDomainDomainTest extends SapphireTest |
||
10 | { |
||
11 | /** |
||
12 | * Set up some test domain data for testing |
||
13 | * |
||
14 | * {@inheritDoc} |
||
15 | */ |
||
16 | public function setUp() |
||
46 | |||
47 | /** |
||
48 | * Test that a hostname defined in a constant will override the default configuration, otherwise the default |
||
49 | * configuration for the domain is returned |
||
50 | */ |
||
51 | public function testGetHostname() |
||
60 | |||
61 | /** |
||
62 | * Test that the domain's "resolves to" property is returned for the URL if it is defined, otherwise null |
||
63 | */ |
||
64 | public function testGetUrl() |
||
72 | |||
73 | /** |
||
74 | * Test that a domain can be identified as the primary domain or otherwise |
||
75 | */ |
||
76 | public function testIsPrimary() |
||
81 | |||
82 | /** |
||
83 | * When the request URI matches one of the allowed rules for a domain, the isActive method should return false |
||
84 | */ |
||
85 | public function testIsActiveReturnsFalseWhenRequestUriIsAllowedPath() |
||
91 | |||
92 | /** |
||
93 | * When a subdomain is "allowed" and is requested, subdomains should be allowed through "isActive" as well |
||
94 | * as the primary domain |
||
95 | */ |
||
96 | public function testSubdomainsAllowedInIsActiveWhenConfigured() |
||
106 | |||
107 | /** |
||
108 | * The default behaviour would be that if the current host from the request matchese that of the domain model |
||
109 | * then isActive should be true |
||
110 | */ |
||
111 | public function testReturnActiveIfCurrentHostMatchesDomainsHostname() |
||
119 | |||
120 | /** |
||
121 | * getNativeUrl should not be used on the primary domain |
||
122 | * |
||
123 | * @expectedException Exception |
||
124 | * @expectedExceptionMessage Cannot convert a native URL on the primary domain |
||
125 | */ |
||
126 | public function testGetNativeUrlThrowsExceptionOnPrimaryDomain() |
||
130 | |||
131 | /** |
||
132 | * Test that a URL segment can be added to the domain's URL and returned as a "native URL" |
||
133 | */ |
||
134 | public function testGetNativeUrl() |
||
139 | |||
140 | /** |
||
141 | * "Allowed" and "forced" URLs should just be returned from getNativeUrl as is |
||
142 | */ |
||
143 | public function testGetNativeUrlReturnsInputWhenUrlIsAllowedOrForced() |
||
151 | |||
152 | /** |
||
153 | * The primary domain and "allowed" route matches should be returned as it |
||
154 | */ |
||
155 | public function testGetVanityUrlReturnsInputWhenUrlIsAllowedOrIsPrimaryDomain() |
||
160 | |||
161 | /** |
||
162 | * Non-primary domains and un-allowed route matches should be returned without their URL for vanity |
||
163 | */ |
||
164 | public function testGetVanityUrl() |
||
169 | |||
170 | public function tearDown() |
||
175 | } |
||
176 |
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: