Skip to content

Commit

Permalink
support PHP 8 (#404)
Browse files Browse the repository at this point in the history
* added php8 to travis tests

updated travis file for php 8.0

change camel case

update get class with reflection class

update getName from reflection

fix phpstan

added composer update to travis file

update cs-fixer script

updaye for builtIn reflection function

removed php 7.2

using snake case for test files

* removed if condition

* added test and if condition to check if there is no params

* improve code

* removed unused use statement
  • Loading branch information
AlessandroMinoccheri committed Dec 29, 2020
1 parent 6125a40 commit d2e54ae
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ $config->setFinder(
])
);

$config->setRules([
'php_unit_method_casing' => ['case' => 'snake_case']
]);

return $config;
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ cache:
- vendor

php:
- 7.2
- 7.3
- 7.4
- 8.0

before_install:
# Disable XDebug speed up test execution. (Ignore failures if platform does not had the extension installed)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ php-cs-fixer:

.PHONY: php-cs-fixer-ci
php-cs-fixer-ci:
vendor/bin/php-cs-fixer fix --dry-run --no-interaction --allow-risky=yes --diff --verbose
PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run --no-interaction --allow-risky=yes --diff --verbose

PHONY: phpstan
phpstan:
Expand Down
13 changes: 7 additions & 6 deletions src/Broadway/CommandHandling/ClosureCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ class ClosureCommandHandler implements CommandHandler
public function add(\Closure $handler): void
{
$reflection = new \ReflectionFunction($handler);
$reflectionParams = $reflection->getParameters();

if (!isset($reflectionParams[0]) || !$reflectionParams[0]->getClass()) {
if (0 === $reflection->getNumberOfParameters()) {
throw new ClosureParameterNotAnObjectException();
}

$index = $reflectionParams[0]->getClass()->getName();

$this->handlers[$index] = $handler;
$reflectionType = $reflection->getParameters()[0]->getType();
if ($reflectionType instanceof \ReflectionNamedType && !$reflectionType->isBuiltin()) {
$this->handlers[$reflectionType->getName()] = $handler;
} else {
throw new ClosureParameterNotAnObjectException();
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/Broadway/CommandHandling/ClosureCommandHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ public function it_throws_when_adding_a_closure_without_an_object_argument()

$commandHandler->add(function ($params = null) { });
}

/**
* @test
*/
public function it_throws_when_adding_a_closure_without_an_object_argument_and_no_params()
{
$commandHandler = new ClosureCommandHandler();
$this->expectException(ClosureParameterNotAnObjectException::class);

$commandHandler->add(function () { });
}
}

class ClosureCommandHandlerTestCommand
Expand Down
4 changes: 2 additions & 2 deletions test/Broadway/Domain/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function it_returns_a_new_instance_when_adding_interval()
* @test
* @dataProvider provideDateDiffs
*/
public function it_diffs_2_dates($date1, $date2, $expectedDiff)
public function it_diffs2_dates($date1, $date2, $expectedDiff)
{
$diff = DateTime::fromString($date1)->diff(DateTime::fromString($date2));

Expand All @@ -85,7 +85,7 @@ public function it_diffs_2_dates($date1, $date2, $expectedDiff)
/**
* @test
*/
public function it_compares_2_dates()
public function it_compares2_dates()
{
$this->assertTrue(DateTime::fromString('2014-01-01T01:01:01.123456+0000')->equals(DateTime::fromString('2014-01-01T01:01:01.123456+0000'))); // exact the same
$this->assertTrue(DateTime::fromString('2014-01-01T01:01:01.123456+02:00')->equals(DateTime::fromString('2014-01-01T01:01:01.123456+0200'))); // different TimeZone format
Expand Down
6 changes: 3 additions & 3 deletions test/Broadway/Domain/DomainMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function it_has_getters()
/**
* @test
*/
public function it_returns_a_new_instance_with_more_metadata_on_andMetadata()
public function it_returns_a_new_instance_with_more_metadata_on_and_metadata()
{
$domainMessage = DomainMessage::recordNow('id', 42, new Metadata(), 'payload');

Expand All @@ -51,7 +51,7 @@ public function it_returns_a_new_instance_with_more_metadata_on_andMetadata()
/**
* @test
*/
public function it_keeps_all_data_the_same_expect_metadata_on_andMetadata()
public function it_keeps_all_data_the_same_expect_metadata_on_and_metadata()
{
$domainMessage = DomainMessage::recordNow('id', 42, new Metadata(), 'payload');

Expand All @@ -68,7 +68,7 @@ public function it_keeps_all_data_the_same_expect_metadata_on_andMetadata()
/**
* @test
*/
public function it_merges_the_metadata_instances_on_andMetadata()
public function it_merges_the_metadata_instances_on_and_metadata()
{
$domainMessage = DomainMessage::recordNow('id', 42, Metadata::kv('bar', 1337), 'payload');

Expand Down
4 changes: 2 additions & 2 deletions test/Broadway/EventSourcing/EventSourcingRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function createAggregate()
/**
* @test
*/
public function it_throws_an_exception_when_instantiated_with_a_class_that_is_not_an_EventSourcedAggregateRoot()
public function it_throws_an_exception_when_instantiated_with_a_class_that_is_not_an_event_sourced_aggregate_root()
{
$this->expectException(InvalidArgumentException::class);

Expand All @@ -47,7 +47,7 @@ public function it_throws_an_exception_when_instantiated_with_a_class_that_is_no
/**
* @test
*/
public function it_can_use_an_alternative_AggregateFactory_to_create_the_Aggregate()
public function it_can_use_an_alternative_aggregate_factory_to_create_the_aggregate()
{
// make sure events exist in the event store
$id = 'y0l0';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MetadataEnrichingEventStreamDecoratorTest extends TestCase
/**
* @test
*/
public function it_returns_the_original_eventStream_if_no_enrichers_are_registered()
public function it_returns_the_original_event_stream_if_no_enrichers_are_registered()
{
$decorator = new MetadataEnrichingEventStreamDecorator();

Expand Down
6 changes: 3 additions & 3 deletions test/Broadway/Serializer/SimpleInterfaceSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function setUp(): void
/**
* @test
*/
public function it_throws_an_exception_if_an_object_does_not_implement_Serializable()
public function it_throws_an_exception_if_an_object_does_not_implement_serializable()
{
$this->expectException(SerializationException::class);
$this->expectExceptionMessage(sprintf(
Expand Down Expand Up @@ -72,7 +72,7 @@ public function it_throws_an_exception_if_payload_not_set_in_data()
/**
* @test
*/
public function it_serializes_objects_implementing_Serializable()
public function it_serializes_objects_implementing_serializable()
{
$object = new TestSerializable('bar');

Expand All @@ -85,7 +85,7 @@ public function it_serializes_objects_implementing_Serializable()
/**
* @test
*/
public function it_deserializes_classes_implementing_Serializable()
public function it_deserializes_classes_implementing_serializable()
{
$data = ['class' => 'Broadway\Serializer\TestSerializable', 'payload' => ['foo' => 'bar']];

Expand Down

0 comments on commit d2e54ae

Please sign in to comment.