Skip to content

Commit

Permalink
Convert newinstance to anonymous classes
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Apr 10, 2020
1 parent d78c411 commit bd89acb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/test/php/img/unittest/GifImageWriterTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use img\ImagingException;
use img\io\GifStreamWriter;
use io\{FileUtil, IOException};
use io\streams\{MemoryOutputStream, OutputStream};
use io\{FileUtil, IOException};

/**
* Tests writing GIF images
Expand All @@ -16,11 +16,11 @@ class GifImageWriterTest extends AbstractImageWriterTest {

#[@test, @expect(ImagingException::class)]
public function write_error() {
$this->image->saveTo(new GifStreamWriter(newinstance(OutputStream::class, [], [
'write' => function($arg) { throw new IOException('Could not write: Intentional exception'); },
'flush' => function() { },
'close' => function() { }
])));
$this->image->saveTo(new GifStreamWriter(new class() implements OutputStream {
public function write($arg) { throw new IOException('Could not write: Intentional exception'); }
public function flush() { }
public function close() { }
}));
}

#[@test]
Expand Down
15 changes: 7 additions & 8 deletions src/test/php/img/unittest/ImageReaderTest.class.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php namespace img\unittest;

use img\{Image, ImagingException};
use img\io\{GifStreamReader, JpegStreamReader, PngStreamReader};
use io\{FileUtil, IOException};
use img\{Image, ImagingException};
use io\streams\{InputStream, MemoryInputStream};
use io\{FileUtil, IOException};
use lang\Runtime;
use unittest\TestCase;

Expand All @@ -17,12 +17,11 @@ class ImageReaderTest extends TestCase {

#[@test, @expect(ImagingException::class)]
public function readError() {
$s= newinstance(InputStream::class, [], [
'read' => function($limit= 8192) { throw new IOException('Could not read: Intentional exception'); },
'available' => function() { return 1; },
'close' => function() { }
]);
Image::loadFrom(new GifStreamReader($s));
Image::loadFrom(new GifStreamReader(new class() implements InputStream {
public function read($limit= 8192) { throw new IOException('Could not read: Intentional exception'); }
public function available() { return 1; }
public function close() { }
}));
}

#[@test, @expect(ImagingException::class)]
Expand Down
12 changes: 6 additions & 6 deletions src/test/php/img/unittest/JpegImageWriterTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use img\ImagingException;
use img\io\JpegStreamWriter;
use io\{FileUtil, IOException};
use io\streams\{MemoryOutputStream, OutputStream};
use io\{FileUtil, IOException};

/**
* Tests writing JPEG images
Expand All @@ -16,11 +16,11 @@ class JpegImageWriterTest extends AbstractImageWriterTest {

#[@test, @expect(ImagingException::class)]
public function write_error() {
$this->image->saveTo(new JpegStreamWriter(newinstance(OutputStream::class, [], [
'write' => function($arg) { throw new IOException('Could not write: Intentional exception'); },
'flush' => function() { },
'close' => function() { }
])));
$this->image->saveTo(new JpegStreamWriter(new class() implements OutputStream {
public function write($arg) { throw new IOException('Could not write: Intentional exception'); }
public function flush() { }
public function close() { }
}));
}

#[@test]
Expand Down
12 changes: 6 additions & 6 deletions src/test/php/img/unittest/PngImageWriterTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use img\ImagingException;
use img\io\PngStreamWriter;
use io\{FileUtil, IOException};
use io\streams\{MemoryOutputStream, OutputStream};
use io\{FileUtil, IOException};

/**
* Tests writing PNG images
Expand All @@ -19,11 +19,11 @@ protected function imageType() { return 'PNG'; }

#[@test, @expect(ImagingException::class)]
public function write_error() {
$this->image->saveTo(new PngStreamWriter(newinstance(OutputStream::class, [], [
'write' => function($arg) { throw new IOException('Could not write: Intentional exception'); },
'flush' => function() { },
'close' => function() { }
])));
$this->image->saveTo(new PngStreamWriter(new class() implements OutputStream {
public function write($arg) { throw new IOException('Could not write: Intentional exception'); }
public function flush() { }
public function close() { }
}));
}

#[@test]
Expand Down

0 comments on commit bd89acb

Please sign in to comment.