2016-12-29 14:09:49 -06:00
|
|
|
<?php
|
2016-08-16 16:39:25 -05:00
|
|
|
|
2015-05-13 10:05:23 -04:00
|
|
|
namespace Amp\Test;
|
|
|
|
|
2016-07-19 00:05:40 -05:00
|
|
|
class StructTestFixture {
|
|
|
|
use \Amp\Struct;
|
|
|
|
public $callback;
|
2017-01-07 22:55:34 +01:00
|
|
|
public $_foofoofoofoofoofoofoofoobar;
|
2016-07-19 00:05:40 -05:00
|
|
|
}
|
|
|
|
|
2015-05-13 10:05:23 -04:00
|
|
|
class StructTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
/**
|
2016-08-12 16:58:53 -05:00
|
|
|
* @expectedException \Error
|
2015-07-29 23:23:53 -04:00
|
|
|
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callbac" does not exist ... did you mean "callback?"
|
2015-05-13 10:05:23 -04:00
|
|
|
*/
|
|
|
|
public function testSetErrorWithSuggestion() {
|
2015-07-29 23:23:53 -04:00
|
|
|
$struct = new StructTestFixture;
|
2015-05-13 10:05:23 -04:00
|
|
|
$struct->callbac = function(){};
|
|
|
|
}
|
2015-07-29 23:23:53 -04:00
|
|
|
|
2015-05-13 10:05:23 -04:00
|
|
|
/**
|
2016-08-12 16:58:53 -05:00
|
|
|
* @expectedException \Error
|
2015-07-29 23:23:53 -04:00
|
|
|
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callbac" does not exist ... did you mean "callback?"
|
2015-05-13 10:05:23 -04:00
|
|
|
*/
|
|
|
|
public function testGetErrorWithSuggestion() {
|
2015-07-29 23:23:53 -04:00
|
|
|
$struct = new StructTestFixture;
|
2015-05-13 10:05:23 -04:00
|
|
|
$test = $struct->callbac;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-12 16:58:53 -05:00
|
|
|
* @expectedException \Error
|
2015-07-29 23:23:53 -04:00
|
|
|
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callZZZZZZZZZZZ" does not exist
|
2015-05-13 10:05:23 -04:00
|
|
|
*/
|
|
|
|
public function testSetErrorWithoutSuggestion() {
|
2015-07-29 23:23:53 -04:00
|
|
|
$struct = new StructTestFixture;
|
2015-05-13 10:05:23 -04:00
|
|
|
$struct->callZZZZZZZZZZZ = "test";
|
|
|
|
}
|
2015-07-29 23:23:53 -04:00
|
|
|
|
2015-05-13 10:05:23 -04:00
|
|
|
/**
|
2016-08-12 16:58:53 -05:00
|
|
|
* @expectedException \Error
|
2015-07-29 23:23:53 -04:00
|
|
|
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callZZZZZZZZZZZ" does not exist
|
2015-05-13 10:05:23 -04:00
|
|
|
*/
|
|
|
|
public function testGetErrorWithoutSuggestion() {
|
2015-07-29 23:23:53 -04:00
|
|
|
$struct = new StructTestFixture;
|
2015-05-13 10:05:23 -04:00
|
|
|
$test = $struct->callZZZZZZZZZZZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-12 16:58:53 -05:00
|
|
|
* @expectedException \Error
|
2015-07-29 23:23:53 -04:00
|
|
|
* @expectedExceptionMessage Amp\Test\StructTestFixture property "__propertySuggestThreshold" does not exist
|
2015-05-13 10:05:23 -04:00
|
|
|
*/
|
|
|
|
public function testSuggestionIgnoresPropertyStartingWithUnderscore() {
|
2015-07-29 23:23:53 -04:00
|
|
|
$struct = new StructTestFixture;
|
2015-05-13 10:05:23 -04:00
|
|
|
$test = $struct->__propertySuggestThreshold;
|
|
|
|
}
|
2017-01-07 22:55:34 +01:00
|
|
|
|
|
|
|
public function testSetErrorWithoutSuggestionBecauseUnderscore() {
|
|
|
|
// Use regexp to ensure no property is suggested, because expected message is a prefix then and still passes
|
|
|
|
$this->setExpectedExceptionRegExp(\Error::class, "(Amp\\\\Test\\\\StructTestFixture property \"foofoofoofoofoofoofoofoobar\" does not exist$)");
|
|
|
|
$struct = new StructTestFixture;
|
|
|
|
$struct->foofoofoofoofoofoofoofoobar = "test";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetErrorWithoutSuggestionBecauseUnderscore() {
|
|
|
|
// Use regexp to ensure no property is suggested, because expected message is a prefix then and still passes
|
|
|
|
$this->setExpectedExceptionRegExp(\Error::class, "(Amp\\\\Test\\\\StructTestFixture property \"foofoofoofoofoofoofoofoobar\" does not exist$)");
|
|
|
|
$struct = new StructTestFixture;
|
|
|
|
$test = $struct->foofoofoofoofoofoofoofoobar;
|
|
|
|
}
|
2015-05-13 10:05:23 -04:00
|
|
|
}
|