public function testWillNotProceedExecuteOnWriteAndCrash()
 {
     $this->fieldAccess->expects($this->never())->method('proceed')->will($this->returnValue('done'));
     $this->fieldAccess->expects($this->once())->method('getAccessType')->will($this->returnValue(FieldAccess::WRITE));
     foreach ($this->callables as $callable) {
         $callable->expects($this->any())->method('__invoke')->will($this->throwException(new \Exception()));
     }
     $aspect = new PropertyWriteAspect(...$this->callables);
     $this->setExpectedException(\Exception::class);
     $aspect->beforePropertyAccess($this->fieldAccess);
 }
 public function testWillFailOnInvalidAssignedType()
 {
     $field = new ReflectionProperty(ClassWithGenericArrayTypedProperty::class, 'property');
     $this->fieldAccess->expects($this->any())->method('getAccessType')->will($this->returnValue(FieldAccess::WRITE));
     $this->fieldAccess->expects($this->any())->method('getField')->will($this->returnValue($field));
     $this->fieldAccess->expects($this->any())->method('getValueToSet')->will($this->returnValue('new value'));
     $immutablePropertyCheck = new PropertyWriteTypeChecker();
     // catching the exception raised by PHPUnit by converting a fatal into an exception (in the error handler)
     $this->setExpectedException(\PHPUnit_Framework_Error::class);
     $immutablePropertyCheck->__invoke($this->fieldAccess);
 }
 public function testRaisesExceptionWhenFieldAccessIsInvalid()
 {
     $object = new ClassWithImmutableProperty();
     $field = new ReflectionProperty(ClassWithImmutableProperty::class, 'property');
     $object->property = 'initialized';
     $this->fieldAccess->expects($this->any())->method('getThis')->will($this->returnValue($object));
     $this->fieldAccess->expects($this->any())->method('getAccessType')->will($this->returnValue(FieldAccess::WRITE));
     $this->fieldAccess->expects($this->any())->method('getField')->will($this->returnValue($field));
     $immutablePropertyCheck = new PropertyWriteImmutabilityChecker();
     $this->setExpectedException(\RuntimeException::class);
     $immutablePropertyCheck->__invoke($this->fieldAccess);
 }