示例#1
0
 /**
  * Callback for trait sort
  *
  * @param ClassReflection $a
  * @param ClassReflection $b
  *
  * @return int
  */
 protected static function __classSort(ClassReflection $a, ClassReflection $b)
 {
     if ($a->getSort() > $b->getSort()) {
         return -1;
     }
     if ($a->getSort() < $b->getSort()) {
         return 1;
     }
     return 0;
 }
 /**
  * Register class
  *
  * @param $class
  * @param string $pattern
  * @param float $sort
  *
  * @return ClassReflection
  */
 public function register($class, $pattern = null, $sort = null)
 {
     $reflection = new ClassReflection($class, $pattern, $sort);
     if (!$reflection->isSubclassOf(BaseMock::class)) {
         throw new \RuntimeException("Mock classes '{$class}' does not extend from BaseMock");
     }
     if (!$reflection->getPattern()) {
         throw new \RuntimeException("No `pattern` defined for class '{$class}'");
     }
     $this->_classes[] = $reflection;
     return $reflection;
 }
 /**
  * Test match class name
  *
  * @test
  */
 public function testMatchName()
 {
     $reflection = new ClassReflection(DummyClass::class);
     $reflection->setPattern('Foo*Bar');
     $reflection->setSort(100);
     $this->assertTrue($reflection->matchClassName('FooBar'));
     $this->assertTrue($reflection->matchClassName('Foo_Bar'));
     $this->assertTrue($reflection->matchClassName('FooSampleBar'));
     $this->assertFalse($reflection->matchClassName('Foo'));
     $this->assertFalse($reflection->matchClassName('FooBarTest'));
     $this->assertFalse($reflection->matchClassName('TestFooBar'));
 }