public function testClassInitializer() { /* Given */ $dug = new Dug(); $classInitializer = new ClassInitializerSpy(); $dug->setClassInitializer($classInitializer); $source = Source::build(['users', '/[0-9]+/'], UserProvider::class); $dug->register($source); /* When */ $dug->fetch(['users', 1]); /* Then */ assertThat($classInitializer->initializedClass, is(UserProvider::class)); }
/** * @param Reference[] $references * @return array */ private function groupReferences(array $references) { $groups = []; foreach ($references as $reference) { $source = $this->dug->sourceForPath($reference->getPath()); if ($source === null) { throw new RouteNotFoundException($reference->getPath()); } if (!isset($groups[$source->toString()])) { $groups[$source->toString()] = []; } $groups[$source->toString()][] = $reference; } return array_values($groups); }
public function testInjectCallbackClass() { /* Given */ $dug = new Dug(); $source = Source::build(['users', '/[0-9]+/'], UserProvider::class); $dug->register($source); /* When */ $result = $dug->fetch(['users', 1]); /* Then */ assertThat($result[0]['source'], 'UserProvider'); }