1
0
mirror of https://github.com/danog/amp.git synced 2024-11-26 20:15:00 +01:00

misc v1 cleanup

This commit is contained in:
Daniel Lowrey 2015-07-29 23:23:53 -04:00
parent 56b6330114
commit b1f400cad5
10 changed files with 41 additions and 28 deletions

View File

@ -6,8 +6,8 @@ namespace Amp;
* Create a "return" value for a generator coroutine
*
* Prior to PHP7 Generators do not support return expressions. In order to work around
* this language limitation coroutine authors may yield the result of this function to
* indicate a coroutine's "return" value in a cross-version-compatible manner.
* this language limitation amp coroutines can yield the result of this function to
* indicate a coroutine's "return" value in a legacy-compatible way.
*
* Amp users who want their code to work in both PHP5 and PHP7 environments should yield
* this object to indicate coroutine results.

View File

@ -3,7 +3,10 @@
namespace Amp;
/**
* @TODO This class is only necessary for PHP5; use an anonymous class once PHP7 is required
* This class only exists for legacy PHP5; applications should not treat
* it as part of the public API.
*
* @TODO Remove in favor of an anonymous class once PHP 5 is no longer supported
*/
class CoroutineState {
use Struct;

View File

@ -9,6 +9,8 @@ use EvTimer;
use EvSignal;
class EvReactor implements Reactor {
use Struct;
private $loop;
private $watchers = [];
private $immediates = [];

View File

@ -3,6 +3,8 @@
namespace Amp;
class LibeventReactor implements Reactor {
use Struct;
private $base;
private $watchers = [];
private $immediates = [];

View File

@ -3,6 +3,8 @@
namespace Amp;
class NativeReactor implements Reactor {
use Struct;
private $watchers = [];
private $immediates = [];
private $timerOrder = [];
@ -237,7 +239,7 @@ class NativeReactor implements Reactor {
* {@inheritDoc}
*/
public function immediately(callable $callback, array $options = []) {
$watcher = new Watcher;
$watcher = new \StdClass;
$watcher->id = $watcherId = \spl_object_hash($watcher);
$watcher->type = Watcher::IMMEDIATE;
$watcher->callback = $callback;

View File

@ -2,6 +2,9 @@
namespace Amp;
/**
* Coroutines can yield Pause objects to suspend execution until the specified timeout elapses
*/
class Pause implements Promise {
use Placeholder;

View File

@ -7,6 +7,8 @@ namespace Amp;
* @TODO remove code coverage ignore once we're able to install php-uv on travis
*/
class UvReactor implements Reactor {
use Struct;
private $loop;
private $watchers;
private $enabledWatcherCount = 0;

View File

@ -1,10 +1,11 @@
<?php
namespace Amp;
class Watcher {
use Struct;
/**
* This class exists to provide faux enum values in internal Reactor code.
* Applications should not rely upon these values as part of the public API.
*/
final class Watcher {
const IMMEDIATE = 0b00000001;
const TIMER = 0b00000010;
const TIMER_ONCE = 0b00000110;
@ -13,10 +14,4 @@ class Watcher {
const IO_READER = 0b00110000;
const IO_WRITER = 0b01010000;
const SIGNAL = 0b10000000;
public $id;
public $type;
public $callback;
public $callbackData;
public $isEnabled;
}

View File

@ -2,51 +2,49 @@
namespace Amp\Test;
use Amp\Watcher;
class StructTest extends \PHPUnit_Framework_TestCase {
/**
* @expectedException \DomainException
* @expectedExceptionMessage Amp\Watcher property "callbac" does not exist ... did you mean "callback?"
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callbac" does not exist ... did you mean "callback?"
*/
public function testSetErrorWithSuggestion() {
$struct = new Watcher;
$struct = new StructTestFixture;
$struct->callbac = function(){};
}
/**
* @expectedException \DomainException
* @expectedExceptionMessage Amp\Watcher property "callbac" does not exist ... did you mean "callback?"
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callbac" does not exist ... did you mean "callback?"
*/
public function testGetErrorWithSuggestion() {
$struct = new Watcher;
$struct = new StructTestFixture;
$test = $struct->callbac;
}
/**
* @expectedException \DomainException
* @expectedExceptionMessage Amp\Watcher property "callZZZZZZZZZZZ" does not exist
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callZZZZZZZZZZZ" does not exist
*/
public function testSetErrorWithoutSuggestion() {
$struct = new Watcher;
$struct = new StructTestFixture;
$struct->callZZZZZZZZZZZ = "test";
}
/**
* @expectedException \DomainException
* @expectedExceptionMessage Amp\Watcher property "callZZZZZZZZZZZ" does not exist
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callZZZZZZZZZZZ" does not exist
*/
public function testGetErrorWithoutSuggestion() {
$struct = new Watcher;
$struct = new StructTestFixture;
$test = $struct->callZZZZZZZZZZZ;
}
/**
* @expectedException \DomainException
* @expectedExceptionMessage Amp\Watcher property "__propertySuggestThreshold" does not exist
* @expectedExceptionMessage Amp\Test\StructTestFixture property "__propertySuggestThreshold" does not exist
*/
public function testSuggestionIgnoresPropertyStartingWithUnderscore() {
$struct = new Watcher;
$struct = new StructTestFixture;
$test = $struct->__propertySuggestThreshold;
}
}

View File

@ -4,9 +4,15 @@ namespace Amp\Test;
require __DIR__ . "/../vendor/autoload.php";
error_reporting(E_ALL);
class PromisorPrivateImpl implements \Amp\Promisor {
use \Amp\PrivatePromisor;
}
class PromisorPublicImpl implements \Amp\Promisor, \Amp\Promise {
use \Amp\PublicPromisor;
}
class StructTestFixture {
use \Amp\Struct;
public $callback;
}