Example #1
0
 /**
  * Instantiate the container.
  *
  * Objects and parameters can be passed as argument to the constructor.
  *
  * @param array $values The parameters or objects.
  */
 public function __construct(array $values = array())
 {
     parent::__construct($values);
     $this['config_options'] = array();
     $this['config'] = function ($c) {
         return new Config($c['config_options']);
     };
     $this['annotation_manager'] = function () {
         $annotation_manager = new AnnotationManager();
         $annotation_manager->cache = new AnnotationCache(sys_get_temp_dir());
         return $annotation_manager;
     };
     $this['url_factory'] = function () {
         return new UrlFactory();
     };
     $this['url_normalizer'] = function ($c) {
         /** @var Config $config */
         $config = $c['config'];
         return new Normalizer($config->getOption('base_url'));
     };
     $this['page_locator'] = function ($c) {
         /** @var Config $config */
         $config = $c['config'];
         return new DefaultPageLocator((array) $config->getOption('page_namespace_prefix'));
     };
     $this['page_url_matcher_registry'] = function ($c) {
         $page_url_matcher_registry = new PageUrlMatcherRegistry($c['annotation_manager']);
         /** @var Config $config */
         $config = $c['config'];
         foreach ($config->getOption('page_url_matchers') as $matcher_class) {
             $page_url_matcher_registry->add(new $matcher_class());
         }
         return $page_url_matcher_registry;
     };
 }
 /**
  * @expectedException \QATools\QATools\PageObject\Exception\PageUrlMatcherException
  * @expectedExceptionMessage The "@one" annotation is not valid.
  * @expectedExceptionCode \QATools\QATools\PageObject\Exception\PageUrlMatcherException::TYPE_INVALID_ANNOTATION
  */
 public function testInvalidAnnotations()
 {
     $annotation_class = '\\QATools\\QATools\\PageObject\\Annotation\\IMatchUrlAnnotation';
     $annotation = m::mock($annotation_class);
     $annotation->shouldReceive('isValid')->andReturn(false);
     $annotations = array($annotation);
     $matcher = m::mock(self::MATCHER_INTERFACE);
     $matcher->shouldReceive('getPriority')->andReturn(1);
     $matcher->shouldReceive('getAnnotationName')->andReturn('one');
     $matcher->shouldReceive('getAnnotationClass')->andReturn($annotation_class);
     $matcher->shouldReceive('matches')->with('/', $annotations)->never();
     $this->pageUrlMatcherRegistry->add($matcher);
     $this->annotationManager->shouldReceive('getClassAnnotations')->with($this->page, '@one')->andReturn($annotations);
     $this->pageUrlMatcherRegistry->match('/', $this->page);
 }
Example #3
0
 /**
  * Checks if the given page is currently opened in browser.
  *
  * @param Page $page Page to check.
  *
  * @return boolean
  */
 public function opened(Page $page)
 {
     return $this->pageUrlMatcherRegistry->match($this->_session->getCurrentUrl(), $page);
 }