StreamWriterTest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Ddeboer\DataImport\Tests\Writer;
  3. use Ddeboer\DataImport\Writer\AbstractStreamWriter;
  4. abstract class StreamWriterTest extends \PHPUnit_Framework_TestCase
  5. {
  6. protected $stream;
  7. /** @var AbstractStreamWriter */
  8. protected $writer;
  9. protected function tearDown()
  10. {
  11. if (is_resource($this->stream)) {
  12. fclose($this->stream);
  13. $this->stream = null;
  14. }
  15. }
  16. protected function getStream()
  17. {
  18. if (!is_resource($this->stream)) {
  19. $this->stream = fopen('php://temp', 'r+');
  20. }
  21. return $this->stream;
  22. }
  23. /**
  24. * @param string $expected
  25. * @param AbstractStreamWriter $actual
  26. * @param string $message
  27. */
  28. public static function assertContentsEquals($expected, $actual, $message = '')
  29. {
  30. $stream = $actual->getStream();
  31. rewind($stream);
  32. $actual = stream_get_contents($stream);
  33. self::assertEquals($expected, $actual, $message);
  34. }
  35. }