diff --git a/.gitignore b/.gitignore index 1638488..55beef4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ composer.lock Thumbs.db /phpunit.xml *.iml +.phpunit.result.cache diff --git a/composer.json b/composer.json index 24c3663..a366527 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^7.1.3", + "php": "^7.1.3|^8.0.0", "illuminate/bus": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0", "illuminate/console": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0", "illuminate/contracts": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0", @@ -27,7 +27,7 @@ "illuminate/queue": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0", "illuminate/routing": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0", "illuminate/support": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0", - "openzipkin/zipkin": "~2.0.2", + "openzipkin/zipkin": "~2.0.2|3.0.x-dev", "psr/http-message": "~1.0", "ramsey/uuid": "~3.0|~4.0" }, @@ -36,7 +36,7 @@ "guzzlehttp/psr7": "~1.0", "mockery/mockery": "~1.0", "php-amqplib/php-amqplib": "~2.8", - "phpunit/phpunit": "~7.0", + "phpunit/phpunit": "~7.0|~8.0", "vinelab/http": "~1.5", "lucid-arch/laravel-foundation": "^7.0|^8.0", "lucidarch/lucid": "^1.0" diff --git a/docker-compose.yml b/docker-compose.yml index d5fba95..1c12680 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,12 @@ version: '3.7' services: - # Docker Image: https://hub.docker.com/r/vinelab/nginx-php - app: - image: vinelab/nginx-php:7.4 + workspace: + tty: true + build: + context: resources/docker/workspace + args: + PUID: "${PUID:-1000}" + PGID: "${PGID:-1000}" volumes: - - ./:/code:cached + - ./:/var/www/html diff --git a/resources/docker/workspace/Dockerfile b/resources/docker/workspace/Dockerfile new file mode 100644 index 0000000..147b967 --- /dev/null +++ b/resources/docker/workspace/Dockerfile @@ -0,0 +1,29 @@ +FROM php:8.0-cli-alpine + +ARG PUID=1000 +ARG PGID=1000 + +RUN apk add --no-cache --virtual .build-deps \ + # for extensions + $PHPIZE_DEPS \ + && \ + apk add --no-cache \ + bash \ + # for composer + unzip \ + && \ + docker-php-ext-install \ + # for php-amqplib + bcmath \ + && \ + apk del .build-deps + +COPY --from=composer /usr/bin/composer /usr/bin/composer + +# Add a non-root user to prevent files being created with root permissions on host machine. +RUN addgroup -g ${PGID} user && \ + adduser -u ${PUID} -G user -D user + +WORKDIR /var/www/html + +USER user diff --git a/tests/Zipkin/InteractsWithZipkin.php b/tests/Zipkin/InteractsWithZipkin.php index 6a3187c..8af6c5a 100644 --- a/tests/Zipkin/InteractsWithZipkin.php +++ b/tests/Zipkin/InteractsWithZipkin.php @@ -34,12 +34,11 @@ protected function createTracer( /** * @param array $spans - * @return array */ - protected function shiftSpan(array &$spans): array + protected function shiftSpan(array &$spans): Span { /** @var Span $span */ $span = array_shift($spans); - return $span->toArray(); + return $span; } } diff --git a/tests/Zipkin/QueueJobSubscriberTest.php b/tests/Zipkin/QueueJobSubscriberTest.php index 733aaf3..1d21375 100644 --- a/tests/Zipkin/QueueJobSubscriberTest.php +++ b/tests/Zipkin/QueueJobSubscriberTest.php @@ -57,20 +57,20 @@ public function test_job_processed() $reporter->shouldHaveReceived('report')->with(Mockery::on(function ($spans) { $span = $this->shiftSpan($spans); - $parentId = Arr::get($span, 'id'); + $parentId = $span->getSpanId(); $span = $this->shiftSpan($spans); - $this->assertEquals($parentId, Arr::get($span, 'parentId')); - $this->assertEquals('ExampleJob', Arr::get($span, 'name')); - $this->assertEquals('sync', Arr::get($span, 'tags.connection_name')); - $this->assertEquals('default', Arr::get($span, 'tags.queue_name')); + $this->assertEquals($parentId, $span->getParentId()); + $this->assertEquals('ExampleJob', $span->getName()); + $this->assertEquals('sync', Arr::get($span->getTags(), 'connection_name')); + $this->assertEquals('default', Arr::get($span->getTags(), 'queue_name')); $this->assertEquals([ 'primitive' => 'Example Payload', 'fluent' => [ 'name' => 'John Doe', ], - ], json_decode(Arr::get($span, 'tags.job_input'), true)); + ], json_decode(Arr::get($span->getTags(), 'job_input'), true)); return true; })); @@ -112,22 +112,22 @@ public function test_job_failed() $reporter->shouldHaveReceived('report')->with(Mockery::on(function ($spans) { $span = $this->shiftSpan($spans); - $parentId = Arr::get($span, 'id'); + $parentId = $span->getSpanId(); $span = $this->shiftSpan($spans); - $this->assertEquals($parentId, Arr::get($span, 'parentId')); - $this->assertEquals('ExampleJob', Arr::get($span, 'name')); - $this->assertEquals('sync', Arr::get($span, 'tags.connection_name')); - $this->assertEquals('default', Arr::get($span, 'tags.queue_name')); + $this->assertEquals($parentId, $span->getParentId()); + $this->assertEquals('ExampleJob', $span->getName()); + $this->assertEquals('sync', Arr::get($span->getTags(), 'connection_name')); + $this->assertEquals('default', Arr::get($span->getTags(), 'queue_name')); $this->assertEquals([ 'primitive' => 'Example Payload', 'fluent' => [ 'name' => 'John Doe', ], - ], json_decode(Arr::get($span, 'tags.job_input'), true)); - $this->assertEquals('true', Arr::get($span, 'tags.error')); - $this->assertEquals('whatever', Arr::get($span, 'tags.error_message')); + ], json_decode(Arr::get($span->getTags(), 'job_input'), true)); + $this->assertEquals('true', Arr::get($span->getTags(), 'error')); + $this->assertEquals('whatever', Arr::get($span->getTags(), 'error_message')); return true; })); diff --git a/tests/Zipkin/TraceCommandTest.php b/tests/Zipkin/TraceCommandTest.php index b89b12e..8b1297f 100644 --- a/tests/Zipkin/TraceCommandTest.php +++ b/tests/Zipkin/TraceCommandTest.php @@ -36,9 +36,9 @@ public function trace_console_command() $reporter->shouldHaveReceived('report')->with(Mockery::on(function ($spans) { $span = $this->shiftSpan($spans); - $this->assertEquals('artisan example', Arr::get($span, 'name')); - $this->assertEquals('cli', Arr::get($span, 'tags.type')); - $this->assertContains('phpunit', Arr::get($span, 'tags.argv')); + $this->assertEquals('artisan example', $span->getName()); + $this->assertEquals('cli', Arr::get($span->getTags(), 'type')); + $this->assertStringContainsString('phpunit', Arr::get($span->getTags(), 'argv')); return true; })); diff --git a/tests/Zipkin/TraceRequestsTest.php b/tests/Zipkin/TraceRequestsTest.php index a929548..965fc38 100644 --- a/tests/Zipkin/TraceRequestsTest.php +++ b/tests/Zipkin/TraceRequestsTest.php @@ -48,20 +48,20 @@ public function trace_http_requests() $reporter->shouldHaveReceived('report')->with(Mockery::on(function ($spans) { $span = $this->shiftSpan($spans); - $this->assertRegExp('/^POST \/?shipments\/{id}$/', Arr::get($span, 'name')); - $this->assertEquals('http', Arr::get($span, 'tags.type')); - $this->assertEquals('POST', Arr::get($span, 'tags.request_method')); - $this->assertEquals('shipments/3242', Arr::get($span, 'tags.request_path')); - $this->assertEquals('/shipments/3242?token=secret', Arr::get($span, 'tags.request_uri')); - $this->assertContains('application/json', Arr::get($span, 'tags.request_headers')); - $this->assertContains('This value is hidden because it contains sensitive info', Arr::get($span, 'tags.request_headers')); - $this->assertContains('Catherine Dupuy', Arr::get($span, 'tags.request_input')); - $this->assertNotContains('PASSWORD', Arr::get($span, 'tags.request_input')); - $this->assertEquals('127.0.0.1', Arr::get($span, 'tags.request_ip')); - - $this->assertContains('422', Arr::get($span, 'tags.response_status')); - $this->assertContains('application/json', Arr::get($span, 'tags.response_headers')); - $this->assertContains('Unprocessable Entity', Arr::get($span, 'tags.response_content')); + $this->assertRegExp('/^POST \/?shipments\/{id}$/', $span->getName()); + $this->assertEquals('http', Arr::get($span->getTags(), 'type')); + $this->assertEquals('POST', Arr::get($span->getTags(), 'request_method')); + $this->assertEquals('shipments/3242', Arr::get($span->getTags(), 'request_path')); + $this->assertEquals('/shipments/3242?token=secret', Arr::get($span->getTags(), 'request_uri')); + $this->assertStringContainsString('application/json', Arr::get($span->getTags(), 'request_headers')); + $this->assertStringContainsString('This value is hidden because it contains sensitive info', Arr::get($span->getTags(), 'request_headers')); + $this->assertStringContainsString('Catherine Dupuy', Arr::get($span->getTags(), 'request_input')); + $this->assertStringNotContainsString('PASSWORD', Arr::get($span->getTags(), 'request_input')); + $this->assertEquals('127.0.0.1', Arr::get($span->getTags(), 'request_ip')); + + $this->assertStringContainsString('422', Arr::get($span->getTags(), 'response_status')); + $this->assertStringContainsString('application/json', Arr::get($span->getTags(), 'response_headers')); + $this->assertStringContainsString('Unprocessable Entity', Arr::get($span->getTags(), 'response_content')); return true; })); diff --git a/tests/Zipkin/TracerTest.php b/tests/Zipkin/TracerTest.php index fe8e8d0..a0f981d 100644 --- a/tests/Zipkin/TracerTest.php +++ b/tests/Zipkin/TracerTest.php @@ -33,10 +33,10 @@ public function configure_reporter() $reporter->shouldHaveReceived('report')->with(Mockery::on(function ($spans) { $span = $this->shiftSpan($spans); - $this->assertEquals('orders', Arr::get($span, 'localEndpoint.serviceName')); - $this->assertEquals('192.88.105.145', Arr::get($span, 'localEndpoint.ipv4')); - $this->assertEquals('9444', Arr::get($span, 'localEndpoint.port')); - $this->assertEquals(16, strlen(Arr::get($span, 'traceId'))); + $this->assertEquals('orders', $span->getLocalEndpoint()->getServiceName()); + $this->assertEquals('192.88.105.145', $span->getLocalEndpoint()->getIpv4()); + $this->assertEquals('9444', $span->getLocalEndpoint()->getPort()); + $this->assertEquals(16, strlen($span->getTraceId())); return true; })); @@ -53,7 +53,7 @@ public function configure_reporter_using_hostname() $reporter->shouldHaveReceived('report')->with(Mockery::on(function ($spans) { $span = $this->shiftSpan($spans); - $this->assertEquals('127.0.0.1', Arr::get($span, 'localEndpoint.ipv4')); + $this->assertEquals('127.0.0.1', $span->getLocalEndpoint()->getIpv4()); return true; })); } @@ -69,7 +69,7 @@ public function configure_reporter_using_ipv6_address() $reporter->shouldHaveReceived('report')->with(Mockery::on(function ($spans) { $span = $this->shiftSpan($spans); - $this->assertEquals('dec6:dcca:47dc:7c89:5a7c:8d6f:c9b3:96d0', Arr::get($span, 'localEndpoint.ipv6')); + $this->assertEquals('dec6:dcca:47dc:7c89:5a7c:8d6f:c9b3:96d0', $span->getLocalEndpoint()->getIpv6()); return true; })); } @@ -85,7 +85,7 @@ public function configure_reporter_using_128bit_trace_ids() $reporter->shouldHaveReceived('report')->with(Mockery::on(function ($spans) { $span = $this->shiftSpan($spans); - $this->assertEquals(32, strlen(Arr::get($span, 'traceId'))); + $this->assertEquals(32, strlen($span->getTraceId())); return true; })); } @@ -109,11 +109,11 @@ public function customize_spans() $reporter->shouldHaveReceived('report')->with( Mockery::on(function ($spans) use ($startTimestamp, $finishTimestamp) { $span = $this->shiftSpan($spans); - $this->assertEquals('Create Order', Arr::get($span, 'name')); - $this->assertEquals($finishTimestamp - $startTimestamp, Arr::get($span, 'duration')); - $this->assertEquals('api/orders', Arr::get($span, 'tags.request_path')); - $this->assertEquals('Create Payment', Arr::get($span, 'annotations.0.value')); - $this->assertEquals('Update Order Status', Arr::get($span, 'annotations.1.value')); + $this->assertEquals('Create Order', $span->getName()); + $this->assertEquals($finishTimestamp - $startTimestamp, $span->getDuration()); + $this->assertEquals('api/orders', Arr::get($span->getTags(), 'request_path')); + $this->assertEquals('Create Payment', Arr::get($span->getAnnotations(), '0.value')); + $this->assertEquals('Update Order Status', Arr::get($span->getAnnotations(), '1.value')); return true; }) ); @@ -129,7 +129,7 @@ public function control_span_duration() $tracer->flush(); $reporter->shouldHaveReceived('report')->with(Mockery::on(function ($spans) { - $duration = Arr::get($this->shiftSpan($spans), 'duration'); + $duration = $this->shiftSpan($spans)->getDuration(); $this->assertTrue($duration > 0); return true; })); @@ -151,9 +151,9 @@ public function control_span_relationships() $reporter->shouldHaveReceived('report')->with(Mockery::on(function ($spans) { $span = $this->shiftSpan($spans); - $this->assertRegExp($this->getRegexpForUUID(), Arr::get($span, 'tags.uuid')); - $this->assertNotNull(Arr::get($span, 'id')); - $this->assertNull(Arr::get($span, 'parentId')); + $this->assertRegExp($this->getRegexpForUUID(), Arr::get($span->getTags(), 'uuid')); + $this->assertNotNull($span->getSpanId()); + $this->assertNull($span->getParentId()); $spanId = Arr::get($span, 'id'); $span = $this->shiftSpan($spans); @@ -180,7 +180,7 @@ public function set_max_tag_len() $this->assertEquals( 'Value exceeds the maximum allowed length of 10 bytes', - Arr::get($span, 'tags.response_content') + Arr::get($span->getTags(), 'response_content') ); return true;