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 9784da6 commit 658d0e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
34 changes: 17 additions & 17 deletions src/test/php/peer/stomp/unittest/BaseTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ public function setUp() {
}

protected function newConnection(URL $url) {
return newinstance(Connection::class, [$url], [
'response' => '',
'sent' => null,
'in' => null,
'out' => null,
return new class($url) extends Connection {
public $response = '';
public $sent = null;
public $in = null;
public $out = null;

'__construct' => function($url) {
public function __construct($url) {
parent::__construct($url);
$this->_connect($url); // FIXME: Required for unittest
},
}

'_connect' => function(URL $url) {
public function _connect(URL $url) {
$this->in= new StringReader(new MemoryInputStream($this->response));
$this->out= new StringWriter(new MemoryOutputStream());
},
}

'_disconnect' => function() {
public function _disconnect() {
$this->sent= $this->out->getStream()->getBytes();
$this->in= null;
$this->out= null;
},
}

'setResponseBytes' => function($s) {
public function setResponseBytes($s) {
$this->in= new StringReader(new MemoryInputStream($s));
$this->response= $s;
},
}

'readSentBytes' => function() {
public function readSentBytes() {

// Case of DISCONNECT
if (null !== $this->sent) {
Expand All @@ -53,12 +53,12 @@ protected function newConnection(URL $url) {
}

return $this->out->getStream()->getBytes();
},
}

'clearSentBytes' => function() {
public function clearSentBytes() {
$this->_connect(new URL());
$this->sent= null;
}
]);
};
}
}
18 changes: 7 additions & 11 deletions src/test/php/peer/stomp/unittest/StompFrameTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@
use lang\IllegalArgumentException;
use peer\stomp\Header;
use peer\stomp\frame\Frame;
use unittest\TestCase;

/**
* Tests STOMP frame class
*
* @see xp://peer.stomp.unittest.StompSendFrameTest
* @see xp://peer.stomp.frame.Frame
*/
class StompFrameTest extends \unittest\TestCase {
protected $fixture= null;
class StompFrameTest extends TestCase {
private $fixture= null;

/**
* Sets up unittest and creates fixture
*
*/
/** @return void */
public function setUp() {
$this->fixture= newinstance(Frame::class, [], '{
public function command() {
return "test";
}
}');
$this->fixture= new class() extends Frame {
public function command() { return 'test'; }
};
}

#[@test]
Expand Down

0 comments on commit 658d0e9

Please sign in to comment.