Skip to content

Commit

Permalink
Use adventage of newer PHPUnit sytax
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Nov 11, 2017
1 parent 0eed145 commit 2bc2a80
Show file tree
Hide file tree
Showing 140 changed files with 716 additions and 716 deletions.
4 changes: 2 additions & 2 deletions tests/TestCase/Auth/BasicAuthenticateTest.php
Expand Up @@ -214,12 +214,12 @@ public function testAuthenticateSuccess()
/**
* test scope failure.
*
* @expectedException \Cake\Network\Exception\UnauthorizedException
* @expectedExceptionCode 401
* @return void
*/
public function testAuthenticateFailReChallenge()
{
$this->expectException(\Cake\Network\Exception\UnauthorizedException::class);
$this->expectExceptionCode(401);
$this->auth->config('scope.username', 'nate');
$request = new ServerRequest([
'url' => 'posts/index',
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Auth/ControllerAuthorizeTest.php
Expand Up @@ -49,11 +49,11 @@ public function setUp()
}

/**
* @expectedException \Cake\Core\Exception\Exception
* @return void
*/
public function testControllerErrorOnMissingMethod()
{
$this->expectException(\Cake\Core\Exception\Exception::class);
$this->auth->controller(new Controller());
}

Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Auth/DigestAuthenticateTest.php
Expand Up @@ -107,12 +107,12 @@ public function testAuthenticateNoData()
/**
* test the authenticate method
*
* @expectedException \Cake\Network\Exception\UnauthorizedException
* @expectedExceptionCode 401
* @return void
*/
public function testAuthenticateWrongUsername()
{
$this->expectException(\Cake\Network\Exception\UnauthorizedException::class);
$this->expectExceptionCode(401);
$request = new ServerRequest('posts/index');
$request->addParams(['pass' => []]);

Expand Down Expand Up @@ -351,12 +351,12 @@ public function testAuthenticateSuccessSimulatedRequestMethod()
/**
* test scope failure.
*
* @expectedException \Cake\Network\Exception\UnauthorizedException
* @expectedExceptionCode 401
* @return void
*/
public function testAuthenticateFailReChallenge()
{
$this->expectException(\Cake\Network\Exception\UnauthorizedException::class);
$this->expectExceptionCode(401);
$this->auth->config('scope.username', 'nate');
$request = new ServerRequest([
'url' => 'posts/index',
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Auth/PasswordHasherFactoryTest.php
Expand Up @@ -49,12 +49,12 @@ public function testBuild()
/**
* test build() throws exception for non existent hasher
*
* @expectedException \RuntimeException
* @expectedExceptionMessage Password hasher class "FooBar" was not found.
* @return void
*/
public function testBuildException()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Password hasher class "FooBar" was not found.');
$hasher = PasswordHasherFactory::build('FooBar');
}
}
20 changes: 10 additions & 10 deletions tests/TestCase/Cache/CacheTest.php
Expand Up @@ -293,33 +293,33 @@ public function testConfigWithLibAndPluginEngines()
/**
* Test write from a config that is undefined.
*
* @expectedException \InvalidArgumentException
* @return void
*/
public function testWriteNonExistingConfig()
{
$this->expectException(\InvalidArgumentException::class);
$this->assertFalse(Cache::write('key', 'value', 'totally fake'));
}

/**
* Test write from a config that is undefined.
*
* @expectedException \InvalidArgumentException
* @return void
*/
public function testIncrementNonExistingConfig()
{
$this->expectException(\InvalidArgumentException::class);
$this->assertFalse(Cache::increment('key', 1, 'totally fake'));
}

/**
* Test write from a config that is undefined.
*
* @expectedException \InvalidArgumentException
* @return void
*/
public function testDecrementNonExistingConfig()
{
$this->expectException(\InvalidArgumentException::class);
$this->assertFalse(Cache::decrement('key', 1, 'totally fake'));
}

Expand Down Expand Up @@ -364,11 +364,11 @@ public function testConfigVariants($config)
/**
* testConfigInvalidEngine method
*
* @expectedException \BadMethodCallException
* @return void
*/
public function testConfigInvalidEngine()
{
$this->expectException(\BadMethodCallException::class);
$config = ['engine' => 'Imaginary'];
Cache::setConfig('test', $config);
Cache::engine('test');
Expand All @@ -377,11 +377,11 @@ public function testConfigInvalidEngine()
/**
* test that trying to configure classes that don't extend CacheEngine fail.
*
* @expectedException \BadMethodCallException
* @return void
*/
public function testConfigInvalidObject()
{
$this->expectException(\BadMethodCallException::class);
$this->getMockBuilder(\StdClass::class)
->setMockClassName('RubbishEngine')
->getMock();
Expand All @@ -394,11 +394,11 @@ public function testConfigInvalidObject()
/**
* Ensure you cannot reconfigure a cache adapter.
*
* @expectedException \BadMethodCallException
* @return void
*/
public function testConfigErrorOnReconfigure()
{
$this->expectException(\BadMethodCallException::class);
Cache::setConfig('tests', ['engine' => 'File', 'path' => TMP]);
Cache::setConfig('tests', ['engine' => 'Apc']);
}
Expand Down Expand Up @@ -518,10 +518,10 @@ public function testGroupConfigsWithCacheInstance()

/**
* testGroupConfigsThrowsException method
* @expectedException \InvalidArgumentException
*/
public function testGroupConfigsThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
Cache::groupConfigs('bogus');
}

Expand Down Expand Up @@ -589,12 +589,12 @@ public function testWriteEmptyValues()
/**
* testWriteEmptyValues method
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage An empty value is not valid as a cache key
* @return void
*/
public function testWriteEmptyKey()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('An empty value is not valid as a cache key');
$this->_configCache();
Cache::write(null, 'not null', 'tests');
}
Expand Down Expand Up @@ -656,11 +656,11 @@ public function testDeleteMany()
/**
* Test that failed writes cause errors to be triggered.
*
* @expectedException \PHPUnit\Framework\Error\Error
* @return void
*/
public function testWriteTriggerError()
{
$this->expectException(\PHPUnit\Framework\Error\Error::class);
static::setAppNamespace();
Cache::setConfig('test_trigger', [
'engine' => 'TestAppCache',
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Cache/Engine/FileEngineTest.php
Expand Up @@ -418,7 +418,7 @@ public function testPathDoesNotExist()
]);

Cache::read('Test', 'file_test');
$this->assertTrue(file_exists($dir), 'Dir should exist.');
$this->assertFileExists($dir, 'Dir should exist.');

// Cleanup
rmdir($dir);
Expand All @@ -441,7 +441,7 @@ public function testPathDoesNotExistDebugOff()
]);

Cache::read('Test', 'file_test');
$this->assertTrue(file_exists($dir), 'Dir should exist.');
$this->assertFileExists($dir, 'Dir should exist.');

// Cleanup
rmdir($dir);
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Cache/Engine/MemcachedEngineTest.php
Expand Up @@ -152,12 +152,12 @@ public function testOptionsSetting()
/**
* test accepts only valid serializer engine
*
* @expectedException InvalidArgumentException
* @expectedExceptionMessage invalid_serializer is not a valid serializer engine for Memcached
* @return void
*/
public function testInvalidSerializerSetting()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('invalid_serializer is not a valid serializer engine for Memcached');
$Memcached = new MemcachedEngine();
$config = [
'className' => 'Memcached',
Expand Down Expand Up @@ -338,12 +338,12 @@ public function testIgbinarySerializerThrowException()
* test using authentication without memcached installed with SASL support
* throw an exception
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Memcached extension is not build with SASL support
* @return void
*/
public function testSaslAuthException()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Memcached extension is not build with SASL support');
$this->skipIf(
method_exists(Memcached::class, 'setSaslAuthData'),
'Cannot test exception when sasl has been compiled in.'
Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase/Collection/CollectionTest.php
Expand Up @@ -975,23 +975,23 @@ public function testToJson()
/**
* Tests that only arrays and Traversables are allowed in the constructor
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Only an array or \Traversable is allowed for Collection
* @return void
*/
public function testInvalidConstructorArgument()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Only an array or \Traversable is allowed for Collection');
new Collection('Derp');
}

/**
* Tests that issuing a count will throw an exception
*
* @expectedException \LogicException
* @return void
*/
public function testCollectionCount()
{
$this->expectException(\LogicException::class);
$data = [1, 2, 3, 4];
$collection = new Collection($data);
$collection->count();
Expand Down Expand Up @@ -2429,11 +2429,11 @@ public function testCartesianProduct()
/**
* Tests that an exception is thrown if the cartesian product is called with multidimensional arrays
*
* @expectedException \LogicException
* @return void
*/
public function testCartesianProductMultidimensionalArray()
{
$this->expectException(\LogicException::class);
$collection = new Collection([
[
'names' => [
Expand Down Expand Up @@ -2473,11 +2473,11 @@ public function testTranspose()
/**
* Tests that provided arrays do not have even length
*
* @expectedException \LogicException
* @return void
*/
public function testTransposeUnEvenLengthShouldThrowException()
{
$this->expectException(\LogicException::class);
$collection = new Collection([
['Products', '2012', '2013', '2014'],
['Product A', '200', '100', '50'],
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Collection/Iterator/MapReduceTest.php
Expand Up @@ -88,11 +88,11 @@ public function testEmitFinalInMapper()
/**
* Tests that a reducer is required when there are intermediate results
*
* @expectedException \LogicException
* @return void
*/
public function testReducerRequired()
{
$this->expectException(\LogicException::class);
$data = ['a' => ['one', 'two'], 'b' => ['three', 'four']];
$mapper = function ($row, $key, $mr) {
foreach ($row as $number) {
Expand Down
12 changes: 6 additions & 6 deletions tests/TestCase/Console/CommandCollectionTest.php
Expand Up @@ -53,11 +53,11 @@ public function testConstructor()
* Constructor with invalid class names should blow up
*
* @return void
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Cannot use 'stdClass' for command 'nope' it is not a subclass of Cake\Console\Shell
*/
public function testConstructorInvalidClass()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot use \'stdClass\' for command \'nope\' it is not a subclass of Cake\Console\Shell');
new CommandCollection([
'i18n' => I18nShell::class,
'nope' => stdClass::class
Expand Down Expand Up @@ -112,11 +112,11 @@ public function testAddInstance()
/**
* Instances that are not shells should fail.
*
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Cannot use 'stdClass' for command 'routes' it is not a subclass of Cake\Console\Shell
*/
public function testAddInvalidInstance()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot use \'stdClass\' for command \'routes\' it is not a subclass of Cake\Console\Shell');
$collection = new CommandCollection();
$shell = new stdClass();
$collection->add('routes', $shell);
Expand All @@ -125,11 +125,11 @@ public function testAddInvalidInstance()
/**
* Class names that are not shells should fail
*
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Cannot use 'stdClass' for command 'routes' it is not a subclass of Cake\Console\Shell
*/
public function testInvalidShellClassName()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot use \'stdClass\' for command \'routes\' it is not a subclass of Cake\Console\Shell');
$collection = new CommandCollection();
$collection->add('routes', stdClass::class);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/TestCase/Console/CommandRunnerTest.php
Expand Up @@ -52,12 +52,12 @@ public function setUp()
* Test that the console hook not returning a command collection
* raises an error.
*
* @expectedException \RuntimeException
* @expectedExceptionMessage The application's `console` method did not return a CommandCollection.
* @return void
*/
public function testRunConsoleHookFailure()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('The application\'s `console` method did not return a CommandCollection.');
$app = $this->getMockBuilder(BaseApplication::class)
->setMethods(['console', 'middleware', 'bootstrap'])
->setConstructorArgs([$this->config])
Expand All @@ -69,12 +69,12 @@ public function testRunConsoleHookFailure()
/**
* Test that running with empty argv fails
*
* @expectedException \RuntimeException
* @expectedExceptionMessage Cannot run any commands. No arguments received.
* @return void
*/
public function testRunMissingRootCommand()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Cannot run any commands. No arguments received.');
$app = $this->getMockBuilder(BaseApplication::class)
->setMethods(['middleware', 'bootstrap'])
->setConstructorArgs([$this->config])
Expand All @@ -87,12 +87,12 @@ public function testRunMissingRootCommand()
/**
* Test that running an unknown command raises an error.
*
* @expectedException \RuntimeException
* @expectedExceptionMessage Unknown command `cake nope`. Run `cake --help` to get the list of valid commands.
* @return void
*/
public function testRunInvalidCommand()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Unknown command `cake nope`. Run `cake --help` to get the list of valid commands.');
$app = $this->getMockBuilder(BaseApplication::class)
->setMethods(['middleware', 'bootstrap'])
->setConstructorArgs([$this->config])
Expand Down

0 comments on commit 2bc2a80

Please sign in to comment.