Browse Source

Fix/add tests for methods now emitting warnings.

mark_story 8 years ago
parent
commit
0ee3465daa

+ 4 - 4
tests/TestCase/Mailer/Transport/SmtpTransportTest.php

@@ -362,7 +362,7 @@ class SmtpTransportTest extends TestCase
     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');
 
@@ -506,7 +506,7 @@ class SmtpTransportTest extends TestCase
     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");
@@ -631,7 +631,7 @@ class SmtpTransportTest extends TestCase
         $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']));
 
@@ -684,7 +684,7 @@ class SmtpTransportTest extends TestCase
         $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']));
 

+ 120 - 9
tests/TestCase/View/ViewBuilderTest.php

@@ -45,6 +45,18 @@ class ViewBuilderTest extends TestCase
     }
 
     /**
+     * data provider for string properties.
+     *
+     * @return array
+     */
+    public function boolPropertyProvider()
+    {
+        return [
+            ['autoLayout', true],
+        ];
+    }
+
+    /**
      * data provider for array properties.
      *
      * @return array
@@ -65,8 +77,29 @@ class ViewBuilderTest extends TestCase
      */
     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.');
     }
@@ -79,10 +112,13 @@ class ViewBuilderTest extends TestCase
      */
     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.');
     }
 
     /**
@@ -93,14 +129,89 @@ class ViewBuilderTest extends TestCase
      */
     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');
+        });
     }
 
     /**