2016-12-29 21:09:49 +01:00
|
|
|
<?php
|
2016-08-16 23:39:25 +02:00
|
|
|
|
2015-05-13 16:05:23 +02:00
|
|
|
namespace Amp\Test;
|
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
use Amp\PHPUnit\AsyncTestCase;
|
|
|
|
|
2018-06-18 20:00:01 +02:00
|
|
|
class StructTestFixture
|
|
|
|
{
|
2016-07-19 07:05:40 +02:00
|
|
|
use \Amp\Struct;
|
2020-09-28 05:19:52 +02:00
|
|
|
public \Closure $callback;
|
|
|
|
public string $_foofoofoofoofoofoofoofoobar;
|
2016-07-19 07:05:40 +02:00
|
|
|
}
|
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
class StructTest extends AsyncTestCase
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2020-09-28 05:19:52 +02:00
|
|
|
public function testSetErrorWithSuggestion(): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2020-09-28 05:19:52 +02:00
|
|
|
$this->expectException(\Error::class);
|
|
|
|
$this->expectExceptionMessage('Amp\Test\StructTestFixture property "callbac" does not exist ... did you mean "callback?"');
|
|
|
|
|
2015-07-30 05:23:53 +02:00
|
|
|
$struct = new StructTestFixture;
|
2018-06-18 20:00:01 +02:00
|
|
|
$struct->callbac = function () {
|
|
|
|
};
|
2015-05-13 16:05:23 +02:00
|
|
|
}
|
2015-07-30 05:23:53 +02:00
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
public function testGetErrorWithSuggestion(): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2020-09-28 05:19:52 +02:00
|
|
|
$this->expectException(\Error::class);
|
|
|
|
$this->expectExceptionMessage('Amp\Test\StructTestFixture property "callbac" does not exist ... did you mean "callback?"');
|
|
|
|
|
2015-07-30 05:23:53 +02:00
|
|
|
$struct = new StructTestFixture;
|
2015-05-13 16:05:23 +02:00
|
|
|
$test = $struct->callbac;
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
public function testSetErrorWithoutSuggestion(): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2020-09-28 05:19:52 +02:00
|
|
|
$this->expectException(\Error::class);
|
|
|
|
$this->expectExceptionMessage('Amp\Test\StructTestFixture property "callZZZZZZZZZZZ" does not exist');
|
|
|
|
|
2015-07-30 05:23:53 +02:00
|
|
|
$struct = new StructTestFixture;
|
2015-05-13 16:05:23 +02:00
|
|
|
$struct->callZZZZZZZZZZZ = "test";
|
|
|
|
}
|
2015-07-30 05:23:53 +02:00
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
public function testGetErrorWithoutSuggestion(): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2020-09-28 05:19:52 +02:00
|
|
|
$this->expectException(\Error::class);
|
|
|
|
$this->expectExceptionMessage('Amp\Test\StructTestFixture property "callZZZZZZZZZZZ" does not exist');
|
|
|
|
|
2015-07-30 05:23:53 +02:00
|
|
|
$struct = new StructTestFixture;
|
2015-05-13 16:05:23 +02:00
|
|
|
$test = $struct->callZZZZZZZZZZZ;
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
public function testSuggestionIgnoresPropertyStartingWithUnderscore(): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2020-09-28 05:19:52 +02:00
|
|
|
$this->expectException(\Error::class);
|
|
|
|
$this->expectExceptionMessage('Amp\Test\StructTestFixture property "__propertySuggestThreshold" does not exist');
|
|
|
|
|
2015-07-30 05:23:53 +02:00
|
|
|
$struct = new StructTestFixture;
|
2017-03-11 14:57:03 +01:00
|
|
|
$struct->__propertySuggestThreshold;
|
2015-05-13 16:05:23 +02:00
|
|
|
}
|
2017-01-07 22:55:34 +01:00
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
public function testSetErrorWithoutSuggestionBecauseUnderscore(): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2017-01-07 22:55:34 +01:00
|
|
|
// Use regexp to ensure no property is suggested, because expected message is a prefix then and still passes
|
2017-03-11 14:57:03 +01:00
|
|
|
$this->expectException(\Error::class);
|
2020-09-28 05:19:52 +02:00
|
|
|
$this->expectExceptionMessageMatches("(Amp\\\\Test\\\\StructTestFixture property \"foofoofoofoofoofoofoofoobar\" does not exist$)");
|
2017-03-11 14:57:03 +01:00
|
|
|
|
2017-01-07 22:55:34 +01:00
|
|
|
$struct = new StructTestFixture;
|
|
|
|
$struct->foofoofoofoofoofoofoofoobar = "test";
|
|
|
|
}
|
|
|
|
|
2020-09-28 05:19:52 +02:00
|
|
|
public function testGetErrorWithoutSuggestionBecauseUnderscore(): void
|
2018-06-18 20:00:01 +02:00
|
|
|
{
|
2017-01-07 22:55:34 +01:00
|
|
|
// Use regexp to ensure no property is suggested, because expected message is a prefix then and still passes
|
2017-03-11 14:57:03 +01:00
|
|
|
$this->expectException(\Error::class);
|
2020-09-28 05:19:52 +02:00
|
|
|
$this->expectExceptionMessageMatches("(Amp\\\\Test\\\\StructTestFixture property \"foofoofoofoofoofoofoofoobar\" does not exist$)");
|
2017-03-11 14:57:03 +01:00
|
|
|
|
2017-01-07 22:55:34 +01:00
|
|
|
$struct = new StructTestFixture;
|
2017-03-11 14:57:03 +01:00
|
|
|
$struct->foofoofoofoofoofoofoofoobar;
|
2017-01-07 22:55:34 +01:00
|
|
|
}
|
2015-05-13 16:05:23 +02:00
|
|
|
}
|