| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * This file is part of the Superdesk Web Publisher Templates System. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Copyright 2015 Sourcefabric z.ú. and contributors. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * For the full copyright and license information, please see the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * AUTHORS and LICENSE files distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @copyright 2015 Sourcefabric z.ú | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @license http://www.superdesk.org/license | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | namespace SWP\Component\TemplatesSystem\Tests\Gimme\Context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Doctrine\Common\Cache\ArrayCache; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use SWP\Component\TemplatesSystem\Tests\Article; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use SWP\Component\TemplatesSystem\Gimme\Context\Context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use SWP\Component\TemplatesSystem\Gimme\Meta\Meta; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class ContextTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @var Context | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     protected $context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     public function testInitialization() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $this->context = new Context(new ArrayCache()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         self::assertInstanceOf(Context::class, $this->context); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function testInitializationWithDefaultCOnfigurations() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->context = new Context(new ArrayCache(), __DIR__.'/../../Twig/Node/Resources/meta/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         self::assertCount(1, $this->context->getAvailableConfigs()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     public function testAddingNewConfiguration() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $this->context = new Context(new ArrayCache()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $configuration = $this->context->addNewConfig(__DIR__.'/../../Twig/Node/Resources/meta/article.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         self::assertCount(1, $this->context->getAvailableConfigs()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         self::assertEquals($this->context->getAvailableConfigs()[Article::class], $configuration); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function testAddingNewMeta() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->context = new Context(new ArrayCache(), __DIR__.'/../../Twig/Node/Resources/meta/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $meta = $this->context->getMetaForValue(new Article()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $this->context->registerMeta($meta); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         self::assertInstanceOf(Meta::class, $this->context->article); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         self::assertCount(1, $this->context->getRegisteredMeta()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     public function testIfIsSupported() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $this->context = new Context(new ArrayCache()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         self::assertFalse($this->context->isSupported(new Article())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $this->context->addNewConfig(__DIR__.'/../../Twig/Node/Resources/meta/article.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         self::assertTrue($this->context->isSupported(new Article())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                        
            
                                                                    
                                                                                                        
            
            
                | 68 |  | View Code Duplication |     protected function tearDown() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |         $reflection = new \ReflectionObject($this); | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |         foreach ($reflection->getProperties() as $prop) { | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |             if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |                 $prop->setAccessible(true); | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |                 $prop->setValue($this, null); | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |  | 
            
                        
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.