Skip to content

Commit

Permalink
Merge pull request #113 from FriendsOfCake/3.x-deprecations
Browse files Browse the repository at this point in the history
Fix deprecation errors.
  • Loading branch information
ADmad authored Aug 28, 2019
2 parents cc62c59 + 6f65337 commit 612cef1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function export()
];
$_serialize = 'data';

$this->setResponse($this->getResponse()->withDownload('my-file.csv'));
$this->response = $this->response->withDownload('my-file.csv'));
$this->viewBuilder()->setClassName('CsvView.Csv');
$this->set(compact('data', '_serialize'));
}
Expand Down
5 changes: 0 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<php>
<!-- E_ALL => 32767 -->
<!-- E_ALL & ~E_USER_DEPRECATED => 16383 -->
<ini name="error_reporting" value="16383"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
Expand Down
12 changes: 12 additions & 0 deletions src/View/CsvView.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,16 @@ protected function getBom($csvEncoding)

return isset($this->bomMap[$csvEncoding]) ? $this->bomMap[$csvEncoding] : '';
}

/**
* Gets the response instance.
*
* Added for compatibility with CakePHP 3.7+.
*
* @return \Cake\Http\Response
*/
public function getResponse()
{
return $this->response;
}
}
24 changes: 12 additions & 12 deletions tests/TestCase/View/CsvViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testRenderWithoutView()
$output = $this->view->render(false);

$this->assertSame('user,fake,list,item1,item2' . PHP_EOL, $output);
$this->assertSame('text/csv', $this->view->response->getType());
$this->assertSame('text/csv', $this->view->getResponse()->getType());
}

/**
Expand Down Expand Up @@ -132,7 +132,7 @@ public function testRenderWithoutViewMultiple()

$expected = 'a,b,c' . PHP_EOL . '1,2,3' . PHP_EOL . 'you,and,me' . PHP_EOL;
$this->assertSame($expected, $output);
$this->assertSame('text/csv', $this->view->response->getType());
$this->assertSame('text/csv', $this->view->getResponse()->getType());

$this->view->set('_serialize', true);
$output = $this->view->render(false);
Expand All @@ -157,7 +157,7 @@ public function testRenderWithCustomEol()
$output = $this->view->render(false);

$this->assertSame('a,b,c~1,2,3~you,and,me~', $output);
$this->assertSame('text/csv', $this->view->response->getType());
$this->assertSame('text/csv', $this->view->getResponse()->getType());
}

/**
Expand All @@ -181,7 +181,7 @@ public function testRenderWithCustomEncoding()
$expected = iconv('UTF-8', 'SJIS', 'a,b,c' . PHP_EOL . '1,2,3' . PHP_EOL . 'あなた,と,私' . PHP_EOL);

$this->assertSame($expected, $output);
$this->assertSame('text/csv', $this->view->response->getType());
$this->assertSame('text/csv', $this->view->getResponse()->getType());
}

/**
Expand Down Expand Up @@ -211,7 +211,7 @@ public function testRenderWithMbstring()
$expected = mb_convert_encoding('a,b,c' . PHP_EOL . '1,2,3' . PHP_EOL . 'あなた,と,私' . PHP_EOL, 'SJIS', 'UTF-8');

$this->assertSame($expected, $output);
$this->assertSame('text/csv', $this->view->response->getType());
$this->assertSame('text/csv', $this->view->getResponse()->getType());
}

/**
Expand All @@ -233,7 +233,7 @@ public function testRenderWithView()
$output = $this->view->render('index');

$this->assertSame('TEST OUTPUT' . PHP_EOL, $output);
$this->assertSame('text/csv', $this->view->response->getType());
$this->assertSame('text/csv', $this->view->getResponse()->getType());
}

/**
Expand Down Expand Up @@ -271,7 +271,7 @@ public function testRenderViaExtract()
$output = $this->view->render(false);

$this->assertSame('jose,"2010-01-05 00:00:00",beach' . PHP_EOL . 'drew,,ball' . PHP_EOL, $output);
$this->assertSame('text/csv', $this->view->response->getType());
$this->assertSame('text/csv', $this->view->getResponse()->getType());
}

/**
Expand Down Expand Up @@ -310,7 +310,7 @@ public function testRenderViaExtractOptionalField()
$output = $this->view->render(false);

$this->assertSame('1,jose,,beach' . PHP_EOL . '2,drew,ball,fun' . PHP_EOL, $output);
$this->assertSame('text/csv', $this->view->response->getType());
$this->assertSame('text/csv', $this->view->getResponse()->getType());
}

/**
Expand Down Expand Up @@ -350,7 +350,7 @@ function ($row) {
$output = $this->view->render(false);

$this->assertSame('jose,"2010-01-05 00:00:00",my-beach' . PHP_EOL . 'drew,,my-ball' . PHP_EOL, $output);
$this->assertSame('text/csv', $this->view->response->getType());
$this->assertSame('text/csv', $this->view->getResponse()->getType());
}

/**
Expand Down Expand Up @@ -403,7 +403,7 @@ public function testRenderWithSpecialCharacters()
CSV;
$this->assertTextEquals($expected, $output);
$this->assertSame('text/csv', $this->view->response->getType());
$this->assertSame('text/csv', $this->view->getResponse()->getType());
}

/**
Expand Down Expand Up @@ -452,7 +452,7 @@ public function testRenderEnclosure()
$output = $this->view->render(false);

$this->assertSame($expected, $output);
$this->assertSame('text/csv', $this->view->response->getType());
$this->assertSame('text/csv', $this->view->getResponse()->getType());
}
}

Expand All @@ -475,7 +475,7 @@ public function testRenderWithCustomNull()
$output = $this->view->render(false);

$this->assertSame('a,b,c~1,2,NULL~you,NULL,me~', $output);
$this->assertSame('text/csv', $this->view->response->getType());
$this->assertSame('text/csv', $this->view->getResponse()->getType());
}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
use Cake\Core\Configure;
use Cake\Core\Plugin;

/**
* Test suite bootstrap
Expand Down Expand Up @@ -34,4 +33,3 @@
'templates' => [dirname(__FILE__) . DS . 'test_app' . DS . 'TestApp' . DS . 'Template' . DS],
]
]);
Plugin::load('CsvView', ['path' => dirname(dirname(__FILE__)) . DS]);

0 comments on commit 612cef1

Please sign in to comment.