1
0
mirror of https://github.com/danog/amp.git synced 2024-12-11 08:59:46 +01:00
amp/test/StructTest.php

87 lines
2.7 KiB
PHP
Raw Normal View History

<?php
namespace Amp\Test;
2018-06-18 20:00:01 +02:00
class StructTestFixture
{
2016-07-19 07:05:40 +02:00
use \Amp\Struct;
public $callback;
public $_foofoofoofoofoofoofoofoobar;
2016-07-19 07:05:40 +02:00
}
class StructTest extends BaseTest
2018-06-18 20:00:01 +02:00
{
/**
* @expectedException \Error
2018-06-18 20:00:01 +02:00
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callbac" does not exist ... did you mean
* "callback?"
*/
2018-06-18 20:00:01 +02:00
public function testSetErrorWithSuggestion()
{
2015-07-30 05:23:53 +02:00
$struct = new StructTestFixture;
2018-06-18 20:00:01 +02:00
$struct->callbac = function () {
};
}
2015-07-30 05:23:53 +02:00
/**
* @expectedException \Error
2018-06-18 20:00:01 +02:00
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callbac" does not exist ... did you mean
* "callback?"
*/
2018-06-18 20:00:01 +02:00
public function testGetErrorWithSuggestion()
{
2015-07-30 05:23:53 +02:00
$struct = new StructTestFixture;
$test = $struct->callbac;
}
/**
* @expectedException \Error
2015-07-30 05:23:53 +02:00
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callZZZZZZZZZZZ" does not exist
*/
2018-06-18 20:00:01 +02:00
public function testSetErrorWithoutSuggestion()
{
2015-07-30 05:23:53 +02:00
$struct = new StructTestFixture;
$struct->callZZZZZZZZZZZ = "test";
}
2015-07-30 05:23:53 +02:00
/**
* @expectedException \Error
2015-07-30 05:23:53 +02:00
* @expectedExceptionMessage Amp\Test\StructTestFixture property "callZZZZZZZZZZZ" does not exist
*/
2018-06-18 20:00:01 +02:00
public function testGetErrorWithoutSuggestion()
{
2015-07-30 05:23:53 +02:00
$struct = new StructTestFixture;
$test = $struct->callZZZZZZZZZZZ;
}
/**
* @expectedException \Error
2015-07-30 05:23:53 +02:00
* @expectedExceptionMessage Amp\Test\StructTestFixture property "__propertySuggestThreshold" does not exist
*/
2018-06-18 20:00:01 +02:00
public function testSuggestionIgnoresPropertyStartingWithUnderscore()
{
2015-07-30 05:23:53 +02:00
$struct = new StructTestFixture;
$struct->__propertySuggestThreshold;
}
2018-06-18 20:00:01 +02:00
public function testSetErrorWithoutSuggestionBecauseUnderscore()
{
// Use regexp to ensure no property is suggested, because expected message is a prefix then and still passes
$this->expectException(\Error::class);
$this->expectExceptionMessageRegExp("(Amp\\\\Test\\\\StructTestFixture property \"foofoofoofoofoofoofoofoobar\" does not exist$)");
$struct = new StructTestFixture;
$struct->foofoofoofoofoofoofoofoobar = "test";
}
2018-06-18 20:00:01 +02:00
public function testGetErrorWithoutSuggestionBecauseUnderscore()
{
// Use regexp to ensure no property is suggested, because expected message is a prefix then and still passes
$this->expectException(\Error::class);
$this->expectExceptionMessageRegExp("(Amp\\\\Test\\\\StructTestFixture property \"foofoofoofoofoofoofoofoobar\" does not exist$)");
$struct = new StructTestFixture;
$struct->foofoofoofoofoofoofoofoobar;
}
}