*/ LimeAnnotationSupport::enable(); $t = new LimeTest(); // @BeforeAll $file1 = $t->stub('LimeFile'); $file1->getPath()->returns('test1.txt'); $file1->replay(); $file2 = $t->stub('LimeFile'); $file2->getPath()->returns('test2.txt'); $file2->replay(); $file3 = $t->stub('LimeFile'); $file3->getPath()->returns('test3.txt'); $file3->replay(); // @Before $label1 = new LimeLabel(); $label1->addFile($file1); $label1->addFile($file2); $label2 = new LimeLabel(); $label2->addFile($file1); $label2->addFile($file3); // @Test: intersect() returns the intersection of two labels $expected = new LimeLabel(); $expected->addFile($file1); $actual = $label1->intersect($label2); $t->is($actual, $expected, 'The intersection is correct'); // @Test: add() returns the sum of two labels $expected = new LimeLabel(); $expected->addFile($file1); $expected->addFile($file2); $expected->addFile($file3); $actual = $label1->add($label2);
/** * Returns all files with the given labels. * * @param array $labels * @return array */ public function getFilesByLabels(array $labels = array()) { $result = new LimeLabel(); foreach ($this->files as $file) { $result->addFile($file); } if (count($labels) > 0) { foreach ($labels as $label) { if (!preg_match('/^([-+]?)(.+)$/', $label, $matches)) { throw new InvalidArgumentException(sprintf('Invalid label format: %s', $label)); } $operation = $matches[1]; $label = $matches[2]; if (!isset($this->labels[$label])) { throw new InvalidArgumentException(sprintf("Unknown label: %s. Did you mean to run this?\n php lime --test=%s", $label, $label)); } if ($operation == '+') { $result = $result->add($this->labels[$label]); } else { if ($operation == '-') { $result = $result->subtract($this->labels[$label]); } else { $result = $result->intersect($this->labels[$label]); } } } } return $result->getFiles(); }