|
3 | 3 | namespace Packaged\Tests\Context; |
4 | 4 |
|
5 | 5 | use Packaged\Config\Provider\ConfigProvider; |
| 6 | +use Packaged\Context\Conditions\ExpectEnvironment; |
6 | 7 | use Packaged\Context\Context; |
7 | 8 | use Packaged\Event\Channel\Channel; |
8 | 9 | use Packaged\Helpers\Arrays; |
@@ -166,6 +167,58 @@ public function testExtendingContext() |
166 | 167 | $this->assertSame($cnf, $ctx2->getConfig()); |
167 | 168 | $this->assertEquals('def', $ctx2->meta()->get('abc')); |
168 | 169 | $this->assertEquals('456', $ctx2->routeData()->get('123')); |
| 170 | + } |
169 | 171 |
|
| 172 | + /** |
| 173 | + * @param $environment |
| 174 | + * @param $condition |
| 175 | + * @param $expected |
| 176 | + * |
| 177 | + * @return void |
| 178 | + * @dataProvider providerMatches |
| 179 | + */ |
| 180 | + public function testMatches($environment, $condition, $expected) |
| 181 | + { |
| 182 | + $ctx = new Context(); |
| 183 | + $ctx->setEnvironment($environment); |
| 184 | + self::assertEquals($expected, $ctx->matches($condition)); |
| 185 | + } |
| 186 | + |
| 187 | + public function providerMatches() |
| 188 | + { |
| 189 | + return [ |
| 190 | + [Context::ENV_PROD, ExpectEnvironment::prod(), true], |
| 191 | + [Context::ENV_LOCAL, ExpectEnvironment::local(), true], |
| 192 | + [Context::ENV_DEV, ExpectEnvironment::dev(), true], |
| 193 | + [Context::ENV_PHPUNIT, ExpectEnvironment::phpunit(), true], |
| 194 | + [Context::ENV_PROD, ExpectEnvironment::local(), false], |
| 195 | + [Context::ENV_PROD, ExpectEnvironment::dev(), false], |
| 196 | + [Context::ENV_PROD, ExpectEnvironment::phpunit(), false], |
| 197 | + ]; |
| 198 | + } |
| 199 | + |
| 200 | + /** |
| 201 | + * @param $environment |
| 202 | + * @param $conditions |
| 203 | + * @param $expected |
| 204 | + * |
| 205 | + * @return void |
| 206 | + * @dataProvider providerMatchAny |
| 207 | + */ |
| 208 | + public function testMatchAny($environment, array $conditions, $expected) |
| 209 | + { |
| 210 | + $ctx = new Context(); |
| 211 | + $ctx->setEnvironment($environment); |
| 212 | + self::assertEquals($expected, $ctx->matchAny(...$conditions)); |
| 213 | + } |
| 214 | + |
| 215 | + public function providerMatchAny() |
| 216 | + { |
| 217 | + return [ |
| 218 | + [Context::ENV_PROD, [ExpectEnvironment::prod()], true], |
| 219 | + [Context::ENV_PROD, [ExpectEnvironment::prod(), ExpectEnvironment::uat()], true], |
| 220 | + [Context::ENV_UAT, [ExpectEnvironment::prod(), ExpectEnvironment::uat()], true], |
| 221 | + [Context::ENV_LOCAL, [ExpectEnvironment::prod(), ExpectEnvironment::uat()], false], |
| 222 | + ]; |
170 | 223 | } |
171 | 224 | } |
0 commit comments