|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the symfony package. |
| 5 | + * (c) Fabien Potencier <[email protected]> |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + */ |
| 10 | + |
| 11 | +require_once __DIR__.'/../fixtures/myComponent.php'; |
| 12 | +require_once __DIR__.'/../sfContext.class.php'; |
| 13 | +require_once __DIR__.'/../sfNoRouting.class.php'; |
| 14 | +require_once __DIR__.'/../sfEventDispatcherTestCase.php'; |
| 15 | + |
| 16 | +/** |
| 17 | + * @internal |
| 18 | + * |
| 19 | + * @coversNothing |
| 20 | + */ |
| 21 | +class sfComponentTest extends sfEventDispatcherTestCase |
| 22 | +{ |
| 23 | + private sfContext $context; |
| 24 | + |
| 25 | + public function setUp(): void |
| 26 | + { |
| 27 | + $this->context = sfContext::getInstance(array( |
| 28 | + 'routing' => 'sfNoRouting', |
| 29 | + 'request' => 'sfWebRequest', |
| 30 | + )); |
| 31 | + |
| 32 | + $this->testObject = new myComponent($this->context, 'module', 'action'); |
| 33 | + $this->dispatcher = $this->context->getEventDispatcher(); |
| 34 | + $this->class = 'component'; |
| 35 | + } |
| 36 | + |
| 37 | + public function testInitialize() |
| 38 | + { |
| 39 | + $component = new myComponent($this->context, 'module', 'action'); |
| 40 | + $this->assertSame($this->context, $component->getContext(), '->initialize() takes a sfContext object as its first argument'); |
| 41 | + $component->initialize($this->context, 'module', 'action'); |
| 42 | + $this->assertSame($this->context, $component->getContext(), '->initialize() takes a sfContext object as its first argument'); |
| 43 | + } |
| 44 | + |
| 45 | + public function testGetContext() |
| 46 | + { |
| 47 | + $component = new myComponent($this->context, 'module', 'action'); |
| 48 | + |
| 49 | + $component->initialize($this->context, 'module', 'action'); |
| 50 | + $this->assertSame($this->context, $component->getContext(), '->getContext() returns the current context'); |
| 51 | + } |
| 52 | + |
| 53 | + public function testGetRequest() |
| 54 | + { |
| 55 | + $component = new myComponent($this->context, 'module', 'action'); |
| 56 | + |
| 57 | + $component->initialize($this->context, 'module', 'action'); |
| 58 | + $this->assertSame($this->context->getRequest(), $component->getRequest(), '->getRequest() returns the current request'); |
| 59 | + } |
| 60 | + |
| 61 | + public function testGetResponse() |
| 62 | + { |
| 63 | + $component = new myComponent($this->context, 'module', 'action'); |
| 64 | + |
| 65 | + $component->initialize($this->context, 'module', 'action'); |
| 66 | + $this->assertSame($this->context->getResponse(), $component->getResponse(), '->getResponse() returns the current response'); |
| 67 | + } |
| 68 | + |
| 69 | + public function testSetter() |
| 70 | + { |
| 71 | + $component = new myComponent($this->context, 'module', 'action'); |
| 72 | + |
| 73 | + $component->foo = array(); |
| 74 | + $component->foo[] = 'bar'; |
| 75 | + $this->assertSame(array('bar'), $component->foo, '__set() populates component variables'); |
| 76 | + } |
| 77 | +} |
0 commit comments