Skip to content

Commit

Permalink
testCustomClassNameWillNotActivateClassLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotchance committed Oct 18, 2015
1 parent 9b00ae3 commit 0bcd726
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Concise/Mock/ClassCompiler.php
Expand Up @@ -438,7 +438,7 @@ public function setCustomClassName($className)
"Invalid class name '$className'."
);
}
if (class_exists($className)) {
if (class_exists($className, false)) {
throw new InvalidArgumentException(
"You cannot use '$className' because a class with that name already exists."
);
Expand Down
24 changes: 23 additions & 1 deletion tests/Concise/Mock/BuilderCustomClassNameTest.php
Expand Up @@ -31,9 +31,11 @@ public function testCanSetCustomClassName(MockBuilder $builder)
$mock = $builder->setCustomClassName($rand)->get();
$this->assert(get_class($mock))->equals($rand);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage You cannot use 'Concise\Mock\FooClass' because a class with that name already exists.
* @expectedExceptionMessage You cannot use 'Concise\Mock\FooClass' because
* a class with that name already exists.
* @dataProvider allBuilders
* @group #304
*/
Expand All @@ -42,4 +44,24 @@ public function testWillThrowExceptionIfTheCustomNameAlreadyExists(
) {
$builder->setCustomClassName('Concise\Mock\FooClass')->get();
}

/**
* @dataProvider allBuilders
* @group #304
*/
public function testCustomClassNameWillNotActivateClassLoader(
MockBuilder $builder
) {
spl_autoload_register(
function () {
throw new \Exception("Autoloader should not have been called.");
}
);

$rand = "Concise\\Mock\\Temp" . md5(rand());
$builder->setCustomClassName($rand)->get();

$functions = spl_autoload_functions();
spl_autoload_unregister($functions[count($functions) - 1]);
}
}

0 comments on commit 0bcd726

Please sign in to comment.