/** * @test */ public function mergeConstraints() { $tag = 'tag'; $class = 'someClass'; $query = 'tag.someClass'; $firstAttributes = array('attribute1' => 'value1', 'attribute2' => 'value2'); $firstBag = new BagContainer($firstAttributes); $secondAttributes = array('attribute3' => 'value3', 'attribute2' => 'value2x'); $secondBag = new BagContainer($secondAttributes); $firstStylesheetConstraint = new CachingStylesheetConstraint(); $firstConstraint = $this->createStylesheetConstraint($firstAttributes, $tag, $class); $firstStylesheetConstraint->addConstraint($tag, $firstConstraint); $this->writeAttribute($firstStylesheetConstraint, 'resultMap', array($query => $firstBag)); $secondStylesheetConstraint = new CachingStylesheetConstraint(); $secondConstraint = $this->createStylesheetConstraint($secondAttributes, $tag, $class); $secondStylesheetConstraint->addConstraint($tag, $secondConstraint); $this->writeAttribute($secondStylesheetConstraint, 'resultMap', array($query => $secondBag)); $constraint = CachingStylesheetConstraint::merge(array($firstStylesheetConstraint, $secondStylesheetConstraint)); $expectedAttributes = array_merge($firstAttributes, $secondAttributes); $expectedResultMap = array($query => new BagContainer($expectedAttributes)); $this->assertEquals($expectedResultMap, $this->readAttribute($constraint, 'resultMap')); $this->assertEquals(array($firstConstraint, $secondConstraint), $constraint->getConstraints()); }
private function loadStylesheetConstraintFromCache(DataSource $ds) { $id = $ds->getId(); if ($this->cache->test($id)) { $stylesheetConstraint = $this->cache->load($id); } else { $csc = new CachingStylesheetConstraint(); $csc->setCacheId($id); $this->getStylesheetParser()->setRoot($csc); $stylesheetConstraint = $this->parseStylesheet($ds); $this->cache->save($stylesheetConstraint, $id); } return $stylesheetConstraint; }