Skip to content

Commit

Permalink
Fix/add tests for methods now emitting warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Apr 24, 2018
1 parent 2238046 commit 0ee3465
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 13 deletions.
8 changes: 4 additions & 4 deletions tests/TestCase/Mailer/Transport/SmtpTransportTest.php
Expand Up @@ -362,7 +362,7 @@ public function testRcpt()
public function testRcptWithReturnPath()
{
$email = new Email();
$email->from('noreply@cakephp.org', 'CakePHP Test');
$email->setFrom('noreply@cakephp.org', 'CakePHP Test');
$email->setTo('cake@cakephp.org', 'CakePHP');
$email->returnPath('pleasereply@cakephp.org', 'CakePHP Return');

Expand Down Expand Up @@ -506,7 +506,7 @@ public function testGetLastResponse()
public function testGetLastResponseMultipleOperations()
{
$email = new Email();
$email->from('noreply@cakephp.org', 'CakePHP Test');
$email->setFrom('noreply@cakephp.org', 'CakePHP Test');
$email->setTo('cake@cakephp.org', 'CakePHP');

$this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<noreply@cakephp.org>\r\n");
Expand Down Expand Up @@ -631,7 +631,7 @@ public function testKeepAlive()
$email = $this->getMockBuilder('Cake\Mailer\Email')
->setMethods(['message'])
->getMock();
$email->from('noreply@cakephp.org', 'CakePHP Test');
$email->setFrom('noreply@cakephp.org', 'CakePHP Test');
$email->setTo('cake@cakephp.org', 'CakePHP');
$email->expects($this->exactly(2))->method('message')->will($this->returnValue(['First Line']));

Expand Down Expand Up @@ -684,7 +684,7 @@ public function testSendDefaults()
$email = $this->getMockBuilder('Cake\Mailer\Email')
->setMethods(['message'])
->getMock();
$email->from('noreply@cakephp.org', 'CakePHP Test');
$email->setFrom('noreply@cakephp.org', 'CakePHP Test');
$email->setTo('cake@cakephp.org', 'CakePHP');
$email->expects($this->once())->method('message')->will($this->returnValue(['First Line']));

Expand Down
129 changes: 120 additions & 9 deletions tests/TestCase/View/ViewBuilderTest.php
Expand Up @@ -44,6 +44,18 @@ public function stringPropertyProvider()
];
}

/**
* data provider for string properties.
*
* @return array
*/
public function boolPropertyProvider()
{
return [
['autoLayout', true],
];
}

/**
* data provider for array properties.
*
Expand All @@ -65,8 +77,29 @@ public function arrayPropertyProvider()
*/
public function testStringProperties($property, $value)
{
$get = 'get' . ucfirst($property);
$set = 'set' . ucfirst($property);

$builder = new ViewBuilder();
$this->assertNull($builder->{$get}(), 'Default value should be null');
$this->assertSame($builder, $builder->{$set}($value), 'Setter returns this');
$this->assertSame($value, $builder->{$get}(), 'Getter gets value.');
}

/**
* Test string property accessor/mutator methods.
*
* @deprecated
* @dataProvider boolPropertyProvider
* @return void
*/
public function testBoolProperties($property, $value)
{
$get = 'enable' . ucfirst($property);
$set = 'is' . ucfirst($property) . 'Enabled';

$builder = new ViewBuilder();
$this->assertNull($builder->{$property}(), 'Default value should be null');
$this->assertFalse($builder->{$property}(), 'Default value should be null');
$this->assertSame($builder, $builder->{$property}($value), 'Setter returns this');
$this->assertSame($value, $builder->{$property}(), 'Getter gets value.');
}
Expand All @@ -79,10 +112,13 @@ public function testStringProperties($property, $value)
*/
public function testArrayProperties($property, $value)
{
$get = 'get' . ucfirst($property);
$set = 'set' . ucfirst($property);

$builder = new ViewBuilder();
$this->assertSame([], $builder->{$property}(), 'Default value should be empty list');
$this->assertSame($builder, $builder->{$property}($value), 'Setter returns this');
$this->assertSame($value, $builder->{$property}(), 'Getter gets value.');
$this->assertSame([], $builder->{$get}(), 'Default value should be empty list');
$this->assertSame($builder, $builder->{$set}($value), 'Setter returns this');
$this->assertSame($value, $builder->{$get}(), 'Getter gets value.');
}

/**
Expand All @@ -93,14 +129,89 @@ public function testArrayProperties($property, $value)
*/
public function testArrayPropertyMerge($property, $value)
{
$get = 'get' . ucfirst($property);
$set = 'set' . ucfirst($property);

$builder = new ViewBuilder();
$builder->{$property}($value);
$builder->{$set}($value);

$builder->{$set}(['Merged'], true);
$this->assertSame(array_merge($value, ['Merged']), $builder->{$get}(), 'Should merge');

$builder->{$set}($value, false);
$this->assertSame($value, $builder->{$get}(), 'Should replace');
}

/**
* Test string property accessor/mutator methods.
*
* @deprecated
* @dataProvider stringPropertyProvider
* @return void
*/
public function testStringPropertiesDeprecated($property, $value)
{
$this->deprecated(function () {
$builder = new ViewBuilder();
$this->assertNull($builder->{$property}(), 'Default value should be null');
$this->assertSame($builder, $builder->{$property}($value), 'Setter returns this');
$this->assertSame($value, $builder->{$property}(), 'Getter gets value.');
});
}

/**
* Test string property accessor/mutator methods.
*
* @deprecated
* @dataProvider boolPropertyProvider
* @return void
*/
public function testBoolPropertiesDeprecated($property, $value)
{
$this->deprecated(function () {
$builder = new ViewBuilder();
$this->assertNull($builder->{$property}(), 'Default value should be null');
$this->assertSame($builder, $builder->{$property}($value), 'Setter returns this');
$this->assertSame($value, $builder->{$property}(), 'Getter gets value.');
});
}

/**
* Test array property accessor/mutator methods.
*
* @deprecated
* @dataProvider arrayPropertyProvider
* @return void
*/
public function testArrayPropertiesDeprecated($property, $value)
{
$this->deprecated(function () {
$builder = new ViewBuilder();
$this->assertSame([], $builder->{$property}(), 'Default value should be empty list');
$this->assertSame($builder, $builder->{$property}($value), 'Setter returns this');
$this->assertSame($value, $builder->{$property}(), 'Getter gets value.');
});
}

/**
* Test array property accessor/mutator methods.
*
* @deprecated
* @dataProvider arrayPropertyProvider
* @return void
*/
public function testArrayPropertyMergeDeprecated($property, $value)
{
$this->deprecated(function () {
$builder = new ViewBuilder();
$builder->{$property}($value);

$builder->{$property}(['Merged'], true);
$this->assertSame(array_merge($value, ['Merged']), $builder->{$property}(), 'Should merge');
$builder->{$property}(['Merged'], true);
$this->assertSame(array_merge($value, ['Merged']), $builder->{$property}(), 'Should merge');

$builder->{$property}($value, false);
$this->assertSame($value, $builder->{$property}(), 'Should replace');
$builder->{$property}($value, false);
$this->assertSame($value, $builder->{$property}(), 'Should replace');
});
}

/**
Expand Down

0 comments on commit 0ee3465

Please sign in to comment.