Esempio n. 1
0
 public function testExtensions()
 {
     $extension1 = new ExtensionTesting(array('required' => 'value'));
     $extension2 = new ExtensionTesting(array('required' => 'value'));
     $extension3 = new ExtensionTesting(array('required' => 'value'));
     $extension4 = new ExtensionTesting(array('required' => 'value'));
     $mondator = new Mondator();
     $mondator->addExtension($extension1);
     $mondator->addExtension($extension2);
     $this->assertSame(array($extension1, $extension2), $mondator->getExtensions());
     $mondator->setExtensions($extensions = array($extension3, $extension4));
     $this->assertSame($extensions, $mondator->getExtensions());
 }
Esempio n. 2
0
    public function testTwigSupport()
    {
        $mondator = new Mondator();
        $mondator->setConfigClasses(array('Model\\Article' => array('fields' => array('title' => array(), 'content' => array()))));
        $mondator->addExtension(new \Mandango\Mondator\Tests\Fixtures\Extension\Twig\MandangoTestsTwigExtension());
        $containers = $mondator->generateContainers();
        $article = $containers['Model\\Article']->getDefinition('document');
        // properties
        $this->assertTrue($article->hasPropertyByName('publicProperty'));
        $this->assertSame('public', $article->getPropertyByName('publicProperty')->getVisibility());
        $this->assertTrue($article->hasPropertyByName('protectedProperty'));
        $this->assertSame('protected', $article->getPropertyByName('protectedProperty')->getVisibility());
        $this->assertTrue($article->hasPropertyByName('privateProperty'));
        $this->assertSame('private', $article->getPropertyByName('privateProperty')->getVisibility());
        $this->assertTrue($article->hasPropertyByName('staticProperty'));
        $this->assertTrue($article->getPropertyByName('staticProperty')->isStatic());
        $this->assertTrue($article->hasPropertyByName('anotherPublicProperty'));
        $this->assertSame('public', $article->getPropertyByName('anotherPublicProperty')->getVisibility());
        $this->assertTrue($article->hasPropertyByName('anotherProtectedProperty'));
        $this->assertSame('protected', $article->getPropertyByName('anotherProtectedProperty')->getVisibility());
        $this->assertTrue($article->hasPropertyByName('anotherPrivateProperty'));
        $this->assertSame('private', $article->getPropertyByName('anotherPrivateProperty')->getVisibility());
        // methods
        $this->assertTrue($article->hasMethodByName('publicMethod'));
        $this->assertSame('public', $article->getMethodbyName('publicMethod')->getVisibility());
        $this->assertTrue($article->hasMethodByName('protectedMethod'));
        $this->assertSame('protected', $article->getMethodbyName('protectedMethod')->getVisibility());
        $this->assertTrue($article->hasMethodByName('privateMethod'));
        $this->assertSame('private', $article->getMethodbyName('privateMethod')->getVisibility());
        $this->assertTrue($article->hasMethodByName('methodWithPhpDoc'));
        $this->assertSame(<<<EOF
    /**
     * phpDoc
     */
EOF
, $article->getMethodbyName('methodWithPhpDoc')->getDocComment());
        $this->assertTrue($article->hasMethodByName('methodWithArguments'));
        $this->assertSame('$name, $value', $article->getMethodbyName('methodWithArguments')->getArguments());
        $this->assertTrue($article->hasMethodByName('methodWithCode'));
        $this->assertTrue($article->hasMethodByName('methodWithCode'));
        $this->assertSame(<<<EOF
        return null;
EOF
, $article->getMethodbyName('methodWithCode')->getCode());
        $this->assertTrue($article->hasMethodByName('staticMethod'));
        $this->assertTrue($article->getMethodByName('staticMethod')->isStatic());
        $this->assertTrue($article->hasMethodByName('methodWithObjectProperties'));
        $this->assertSame('\\ArrayObject $array, \\Mandango\\Query $query', $article->getMethodbyName('methodWithObjectProperties')->getArguments());
    }