Skip to content

Commit 37ba08e

Browse files
authored
Merge pull request #22 from ray-di/spike
Drop php5.x support refactor
2 parents 51200dc + be96500 commit 37ba08e

File tree

8 files changed

+103
-107
lines changed

8 files changed

+103
-107
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
language: php
22
sudo: false
33
php:
4-
- 5.6
54
- 7
65
- 7.1
7-
- hhvm
6+
- 7.2
87
cache:
98
directories:
109
- vendor

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
"Ray.Di module"
77
],
88
"require": {
9-
"ray/di": "^2.5",
9+
"php": ">=7.0.0",
10+
"ray/di": "^2.7",
1011
"aura/input": "^1.2",
1112
"aura/filter": "^2.3|3.x-dev",
12-
"aura/html": "^2.4",
13-
"ray/aura-session-module": "^1.0"
13+
"aura/html": "^2.5",
14+
"ray/aura-session-module": "^1.1"
1415
},
1516
"require-dev": {
1617
"phpunit/phpunit": "^5.7.13"

src/AuraInputInterceptor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public function invoke(MethodInvocation $invocation)
4545
{
4646
$object = $invocation->getThis();
4747
/* @var $formValidation FormValidation */
48-
$formValidation = $this->reader->getMethodAnnotation($invocation->getMethod(), AbstractValidation::class);
48+
$method = $invocation->getMethod();
49+
$formValidation = $this->reader->getMethodAnnotation($method, AbstractValidation::class);
4950
$form = $this->getFormProperty($formValidation, $object);
5051
$data = $form instanceof SubmitInterface ? $form->submit() : $this->getNamedArguments($invocation);
5152
$isValid = $this->isValid($data, $form);

src/InputValidationInterceptor.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111

1212
class InputValidationInterceptor extends AuraInputInterceptor
1313
{
14-
/**
15-
* @var FailureHandlerInterface
16-
*/
17-
protected $failureHandler;
18-
1914
/**
2015
* @param Reader $reader
2116
* @param FailureHandlerInterface $handler
@@ -24,7 +19,6 @@ class InputValidationInterceptor extends AuraInputInterceptor
2419
*/
2520
public function __construct(Reader $reader, FailureHandlerInterface $handler)
2621
{
27-
$this->reader = $reader;
28-
$this->failureHandler = $handler;
22+
parent::__construct($reader, $handler);
2923
}
3024
}

tests/AbstractFormTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
use Aura\Session\SegmentFactory;
1313
use Aura\Session\Session;
1414
use Doctrine\Common\Annotations\AnnotationReader;
15-
use Ray\Aop\Arguments;
1615
use Ray\Aop\ReflectiveMethodInvocation;
1716
use Ray\WebFormModule\Exception\CsrfViolationException;
18-
use Ray\WebFormModule\Exception\ValidationException;
1917

2018
class AbstractFormTest extends \PHPUnit_Framework_TestCase
2119
{
@@ -47,7 +45,7 @@ public function getMethodInvocation(array $arguments)
4745
return new ReflectiveMethodInvocation(
4846
$controller,
4947
new \ReflectionMethod($controller, 'createAction'),
50-
new Arguments($arguments),
48+
$arguments,
5149
[
5250
$interceptor
5351
]
@@ -63,7 +61,7 @@ public function testApply()
6361

6462
public function testSubmit()
6563
{
66-
$this->setExpectedException(ValidationException::class);
64+
$this->expectException(\ReflectionException::class);
6765
$invocation = $this->getMethodInvocation(['na']);
6866
$invocation->proceed();
6967
}

tests/AuraInputInterceptorTest.php

Lines changed: 83 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,130 +7,137 @@
77
namespace Ray\WebFormModule;
88

99
use Doctrine\Common\Annotations\AnnotationReader;
10-
use Ray\Aop\Arguments;
1110
use Ray\Aop\ReflectiveMethodInvocation;
11+
use Ray\Di\AbstractModule;
12+
use Ray\Di\Injector;
13+
use Ray\Di\InjectorInterface;
1214
use Ray\WebFormModule\Exception\InvalidFormPropertyException;
13-
use Ray\WebFormModule\Exception\InvalidOnFailureMethod;
1415
use Ray\WebFormModule\Exception\ValidationException;
1516

1617
class AuraInputInterceptorTest extends \PHPUnit_Framework_TestCase
1718
{
1819
/**
19-
* @var ReflectiveMethodInvocation
20+
* @var InjectorInterface
2021
*/
21-
private $methodInvocation;
22-
23-
public function setUp()
24-
{
25-
parent::setUp();
26-
}
22+
private $injector;
2723

2824
/**
29-
* @param $method
25+
* @var FakeController
3026
*/
31-
public function getMethodInvocation($method, array $submit, FailureHandlerInterface $handler = null)
32-
{
33-
$handler = $handler ?: new OnFailureMethodHandler;
34-
$object = $this->getController($submit);
27+
private $controller;
3528

36-
return new ReflectiveMethodInvocation(
37-
$object,
38-
new \ReflectionMethod($object, $method),
39-
new Arguments($submit),
40-
[
41-
new AuraInputInterceptor(new AnnotationReader, $handler)
42-
]
43-
);
44-
}
45-
46-
public function getController(array $submit)
29+
public function setUp()
4730
{
48-
$controller = new FakeController;
49-
/** @var $fakeForm FakeForm */
50-
$fakeForm = (new FormFactory)->newInstance(FakeForm::class);
51-
$fakeForm->setSubmit($submit);
52-
$controller->setForm($fakeForm);
53-
54-
return $controller;
31+
$this->injector = new Injector(new class() extends AbstractModule {
32+
protected function configure()
33+
{
34+
$this->install(new AuraInputModule);
35+
$this->bind(FormInterface::class)->annotatedWith('contact_form')->to(FakeForm::class);
36+
}
37+
});
38+
$this->controller = $this->injector->getInstance(FakeController::class);
5539
}
5640

57-
public function proceed($controller)
58-
{
59-
$invocation = new ReflectiveMethodInvocation(
60-
$controller,
61-
new \ReflectionMethod($controller, 'createAction'),
62-
new Arguments([]),
63-
[
64-
new AuraInputInterceptor(new AnnotationReader, new OnFailureMethodHandler)
65-
]
66-
);
67-
$invocation->proceed();
68-
}
41+
// /**
42+
// * @param $method
43+
// */
44+
// public function getMethodInvocation(string $method, array $submit, FailureHandlerInterface $handler = null)
45+
// {
46+
// $handler = $handler ?: new OnFailureMethodHandler;
47+
// $object = $this->getController($submit);
48+
//
49+
// $invocation = new ReflectiveMethodInvocation(
50+
// $object,
51+
// $method,
52+
// $submit,
53+
// [
54+
// new AuraInputInterceptor(new AnnotationReader, $handler)
55+
// ]
56+
// );
57+
//
58+
// return $invocation;
59+
// }
60+
//
61+
// public function getController(array $submit)
62+
// {
63+
// $controller = new FakeController;
64+
// /** @var $fakeForm FakeForm */
65+
// $fakeForm = (new FormFactory)->newInstance(FakeForm::class);
66+
// $fakeForm->setSubmit($submit);
67+
// $controller->setForm($fakeForm);
68+
//
69+
// return $controller;
70+
// }
71+
//
72+
// public function proceed($controller)
73+
// {
74+
// $invocation = new ReflectiveMethodInvocation(
75+
// $controller,
76+
// new \ReflectionMethod($controller, 'createAction'),
77+
// [],
78+
// [
79+
// new AuraInputInterceptor(new AnnotationReader, new OnFailureMethodHandler)
80+
// ]
81+
// );
82+
// $invocation->proceed();
83+
// }
6984

7085
public function testProceedFailed()
7186
{
72-
$invocation = $this->getMethodInvocation('createAction', []);
73-
$result = $invocation->proceed();
87+
$result = $this->controller->createAction([]);
7488
$this->assertSame('400', $result);
7589
}
7690

7791
public function testProceed()
7892
{
79-
$invocation = $this->getMethodInvocation('createAction', ['BEAR']);
80-
$result = $invocation->proceed();
93+
$result = $this->controller->createAction('BEAR');
8194
$this->assertSame('201', $result);
8295
}
8396

8497
public function invalidControllerProvider()
8598
{
8699
return [
87-
[new FakeInvalidController1],
88-
[new FakeInvalidController2]
100+
[$this->injector->getInstance(FakeInvalidController1::class)],
101+
[$this->injector->getInstance(FakeInvalidController2::class)]
89102
];
90103
}
91104

92-
/**
93-
* @dataProvider invalidControllerProvider
94-
*
95-
* @param $controller
96-
*/
97-
public function testInvalidFormPropertyByMissingProperty($controller)
105+
public function testInvalidFormPropertyByMissingProperty()
98106
{
99107
$this->setExpectedException(InvalidFormPropertyException::class);
100-
$this->proceed($controller);
108+
$controller = $this->injector->getInstance(FakeInvalidController1::class);
109+
$controller->createAction();
110+
}
111+
112+
public function testInvalidFormPropertyByMissingProperty2()
113+
{
114+
$this->setExpectedException(InvalidFormPropertyException::class);
115+
$controller = $this->injector->getInstance(FakeInvalidController2::class);
116+
$controller->createAction();
101117
}
102118

103119
public function testInvalidFormPropertyException()
104120
{
105-
$this->setExpectedException(InvalidOnFailureMethod::class);
106-
$controller = new FakeInvalidController3;
107-
/** @var $fakeForm FakeForm */
108-
$fakeForm = (new FormFactory)->newInstance(FakeForm::class);
109-
$fakeForm->setSubmit(['name' => '']);
110-
$controller->setForm($fakeForm);
111-
$this->proceed($controller);
121+
$this->setExpectedException(InvalidFormPropertyException::class);
122+
/** @var FakeInvalidController3 $controller */
123+
$controller = $this->injector->getInstance(FakeInvalidController3::class);
124+
$controller->createAction('');
112125
}
113126

114127
public function testInvalidFormPropertyByInvalidInstance()
115128
{
116129
$this->setExpectedException(InvalidFormPropertyException::class);
117-
$object = new FakeInvalidController1;
118-
$invocation = new ReflectiveMethodInvocation(
119-
$object,
120-
new \ReflectionMethod($object, 'createAction'),
121-
new Arguments(['name' => '']),
122-
[
123-
new AuraInputInterceptor(new AnnotationReader, new OnFailureMethodHandler)
124-
]
125-
);
126-
$invocation->proceed();
130+
$this->setExpectedException(InvalidFormPropertyException::class);
131+
$controller = $this->injector->getInstance(FakeInvalidController1::class);
132+
$controller->createAction('');
127133
}
128134

129135
public function testProceedWithVndErrorHandler()
130136
{
137+
/** @var FakeController $controller */
138+
$controller = $this->injector->getInstance(FakeController::class);
131139
try {
132-
$invocation = $this->getMethodInvocation('createAction', [], new VndErrorHandler(new AnnotationReader));
133-
$invocation->proceed();
140+
$controller->createAction('');
134141
} catch (ValidationException $e) {
135142
$this->assertInstanceOf(FormValidationError::class, $e->error);
136143
$json = (string) $e->error;

tests/AuraInputModuleTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@
1212

1313
class AuraInputModuleTest extends \PHPUnit_Framework_TestCase
1414
{
15-
public function setUp()
16-
{
17-
parent::setUp();
18-
$handler = new FakeSessionHandler();
19-
session_set_save_handler(
20-
[$handler, 'open'],
21-
[$handler, 'close'],
22-
[$handler, 'read'],
23-
[$handler, 'write'],
24-
[$handler, 'destroy'],
25-
[$handler, 'gc']
26-
);
27-
}
28-
2915
public function testAuraInputModule()
3016
{
3117
$injector = new Injector(new FakeModule, __DIR__ . '/tmp');

tests/bootstrap.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@
99
/* @var $loader \Composer\Autoload\ClassLoader */
1010
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
1111
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
12+
13+
$handler = new \Ray\WebFormModule\FakeSessionHandler();
14+
session_set_save_handler(
15+
[$handler, 'open'],
16+
[$handler, 'close'],
17+
[$handler, 'read'],
18+
[$handler, 'write'],
19+
[$handler, 'destroy'],
20+
[$handler, 'gc']
21+
);

0 commit comments

Comments
 (0)