private function detectClass($input, CoveredLine $line) { $line->setClass((bool) preg_match(self::CLASSLINE_PATTERN, $input, $matches)); if ($line->isClass()) { $line->setClassName($matches[1]); } }
public function testGetMethodSkippsConstructor() { $line1 = new CoveredLine("line1"); $line1->setMethod(true); $line1->setMethodName("method1"); $line2 = new CoveredLine("line2"); $line2->setMethod(true); $line2->setMethodName("__construct"); $class = new CoveredClass(); $class->addLine(1, $line1); $class->addLine(2, $line2); $this->assertEquals(array('method1'), $class->getMethods()); }
/** * @param $namespace * @param $classname * @return CoveredClass */ private function createFakeClass($namespace, $classname) { $line0 = new CoveredLine("namespace " . $namespace . ";"); $line1 = new CoveredLine("class " . $classname . "{"); $line1->setClassName($classname); $line1->setClass(true); $line2 = new CoveredLine("}"); $class = new DynamicClassnameCoveredClass(); $class->setName($classname); $class->addLine(0, $line0); $class->addLine(1, $line1); $class->addLine(2, $line2); $class->setNamespace($namespace); return $class; }
public function testLoadClassReturnsTrueOnParsingSuccess() { $class = new DynamicClassnameCoveredClass(); $class->setName("MyOtherName"); $class->setNamespace("MyNamespace"); $class->addLine(0, new CoveredLine("namespace MyNamespace;")); $line1 = new CoveredLine("class MyOtherName{"); $line1->setClass(true); $line1->setClassName("MyOtherName"); $class->addLine(1, $line1); $class->addLine(2, new CoveredLine("}")); $proxy = new ProxyAccessor($class); $proxy->load(); $this->assertTrue($proxy->loadClass($class)); }
public function testMutatorFindsLinesThatAreOnlyNeccessaryWhenAFollowingOneExists() { $line0 = new CoveredLine('$c=0;'); $line0->addCoverage(""); $line1 = new CoveredLine('$c++;'); $line1->addCoverage(""); $this->assertTrue($line0->isEnabled()); $this->assertTrue($line1->isEnabled()); $class = $this->mockClass(array($line0, $line1)); $generator = new MutationGenerator($class); //tester will only validate if everything is enabled or line1 AND line3 are disabled $validatorCallback = function () use($line0, $line1) { if ($line0->isEnabled()) { return true; } return !$line1->isEnabled(); // line0 enabled or both disabled }; $tester = $this->mockTester($validatorCallback); $mutator = new Mutator(); $mutator->testMutations($tester, $generator); $this->assertFalse($line0->isEnabled()); $this->assertFalse($line1->isEnabled()); }
public function testMethodKnowsIfItsAConstructor() { $line = new CoveredLine(""); $line->setMethod(true); $line->setMethodName('__construct'); $this->assertTrue($line->isConstructor()); }