Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true

# JSON files
[*.json]
indent_style = space
indent_size = 4
82 changes: 37 additions & 45 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ name: "Continuous Integration"
on:
push:
paths-ignore:
- 'doc/**'
- '.github/**'
- "doc/**"
pull_request:
paths-ignore:
- 'doc/**'
- '.github/**'
- "doc/**"


jobs:
phpunit:
name: PHP ${{ matrix.php-version }} (${{ matrix.dependency-version }})
name: PHP ${{ matrix.php-version }} (${{ matrix.dependency-versions }})

runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
Expand All @@ -21,53 +20,46 @@ jobs:
fail-fast: false
matrix:
php-version:
- '8.1'
- '8.2'
- '8.3'
- "8.1"
- "8.2"
- "8.3"
- "8.4"
dependency-versions: [lowest, highest]
experimental: [false]
include:
- php-version: '8.4'
dependency-versions: lowest
experimental: true
composer-options: --ignore-platform-reqs
- php-version: '8.4'
dependency-versions: highest
experimental: true
composer-options: --ignore-platform-reqs

steps:
- name: Repository checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3
- name: Repository checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3

- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@efffd0e4f2504f936fcfe3b69293d31ce0e2fd7a # v2.30.3
with:
php-version: ${{ matrix.php-version }}
tools: composer:v2
coverage: pcov

- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@efffd0e4f2504f936fcfe3b69293d31ce0e2fd7a # v2.30.3
with:
php-version: ${{ matrix.php-version }}
tools: composer:v2
coverage: pcov
- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Install dependencies
uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0
with:
dependency-versions: ${{ matrix.dependency-versions }}
composer-options: ${{ matrix.composer-options }}

- name: Install dependencies
uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0
with:
dependency-versions: ${{ matrix.dependency-versions }}
composer-options: ${{ matrix.composer-options }}
- name: Pull the docker image used by the tests.
run: docker pull busybox:latest

- name: Pull the docker image used by the tests.
run: docker pull busybox:latest
- name: Run PHPUnit test suite
run: composer run-script test-ci

- name: Run PHPUnit test suite
run: composer run-script test-ci
- name: Publish code coverage
if: github.repository == 'beluga-php/docker-php' && github.event_name != 'pull_request'
uses: paambaati/codeclimate-action@a1831d7162ea1fbc612ffe5fb3b90278b7999d59 # v5.0.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageCommand: composer run-script test-coverage
coverageLocations: |
${{github.workspace}}/clover.xml:clover

- name: Publish code coverage
uses: paambaati/codeclimate-action@a1831d7162ea1fbc612ffe5fb3b90278b7999d59 # v5.0.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageCommand: composer run-script test-coverage
coverageLocations: |
${{github.workspace}}/clover.xml:clover
if: github.event_name != 'pull_request'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ bin/
composer.lock
.vagrant
/.php-cs-fixer.cache
/.phpunit.result.cache
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"nyholm/psr7": "^1.8",
"php-http/client-common": "^2.7",
"php-http/discovery": "^1.19",
"php-http/socket-client": "^2.1",
"php-http/socket-client": "^2.3",
"psr/http-message": "^2.0",
"symfony/filesystem": "^6.3 || ^7.0",
"symfony/process": "^6.3 || ^7.0",
Expand All @@ -26,8 +26,8 @@
"friendsofphp/php-cs-fixer": "^3.8",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5",
"psy/psysh": "^0.12",
"phpunit/phpunit": "^10.5.46",
"psy/psysh": "^0.12.8",
"roave/security-advisories": "dev-latest"
},
"conflict": {
Expand Down
2 changes: 1 addition & 1 deletion src/Context/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Context implements ContextInterface
* @param string $format Format to use when sending the call (stream or tar: string)
* @param Filesystem $fs filesystem object for cleaning the context directory on destruction
*/
public function __construct($directory, $format = self::FORMAT_STREAM, Filesystem $fs = null)
public function __construct($directory, $format = self::FORMAT_STREAM, ?Filesystem $fs = null)
{
$this->directory = $directory;
$this->format = $format;
Expand Down
2 changes: 1 addition & 1 deletion src/Context/ContextBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ContextBuilder
/**
* @param \Symfony\Component\Filesystem\Filesystem $fs
*/
public function __construct(Filesystem $fs = null)
public function __construct(?Filesystem $fs = null)
{
$this->fs = $fs ?: new Filesystem();
$this->format = Context::FORMAT_STREAM;
Expand Down
2 changes: 1 addition & 1 deletion src/Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function imageBuild($requestBody = null, array $queryParameters = [], arr
/**
* {@inheritdoc}
*/
public function imageCreate(string $requestBody = null, array $queryParameters = [], array $headerParameters = [], string $fetch = self::FETCH_OBJECT)
public function imageCreate(?string $requestBody = null, array $queryParameters = [], array $headerParameters = [], string $fetch = self::FETCH_OBJECT)
{
return $this->executeEndpoint(new ImageCreate($requestBody, $queryParameters, $headerParameters), $fetch);
}
Expand Down
4 changes: 2 additions & 2 deletions src/DockerClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

final class DockerClientFactory
{
public static function create(array $config = [], PluginClientFactory $pluginClientFactory = null): PluginClient
public static function create(array $config = [], ?PluginClientFactory $pluginClientFactory = null): PluginClient
{
if (!\array_key_exists('remote_socket', $config)) {
$config['remote_socket'] = 'unix:///var/run/docker.sock';
Expand Down Expand Up @@ -46,7 +46,7 @@ public static function create(array $config = [], PluginClientFactory $pluginCli
);
}

public static function createFromEnv(PluginClientFactory $pluginClientFactory = null): PluginClient
public static function createFromEnv(?PluginClientFactory $pluginClientFactory = null): PluginClient
{
$options = [
'remote_socket' => getenv('DOCKER_HOST') ? getenv('DOCKER_HOST') : 'unix:///var/run/docker.sock',
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoint/ContainerAttach.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class ContainerAttach extends BaseEndpoint
{
protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, string $contentType = null)
protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null)
{
if (200 === $response->getStatusCode() && DockerRawStream::HEADER === $contentType) {
return new DockerRawStream($response->getBody());
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoint/ExecStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class ExecStart extends BaseEndpoint
{
protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, string $contentType = null)
protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null)
{
if (200 === $response->getStatusCode() && DockerRawStream::HEADER === $contentType) {
return new DockerRawStream($response->getBody());
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoint/ImageBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getBody(SerializerInterface $serializer, $streamFactory = null):
return [['Content-Type' => ['application/octet-stream']], $body];
}

protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, string $contentType = null)
protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null)
{
if (200 === $response->getStatusCode()) {
return new BuildStream($response->getBody(), $serializer);
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoint/ImageCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class ImageCreate extends BaseEndpoint
{
protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, string $contentType = null)
protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null)
{
if (200 === $response->getStatusCode()) {
return new CreateImageStream($response->getBody(), $serializer);
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoint/ImagePush.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getUri(): string
return str_replace(['{name}'], [urlencode($this->name)], '/images/{name}/push');
}

protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, string $contentType = null)
protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null)
{
if (200 === $response->getStatusCode()) {
return new PushStream($response->getBody(), $serializer);
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoint/SystemEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class SystemEvents extends BaseEndpoint
{
protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, string $contentType = null)
protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null)
{
if (200 === $response->getStatusCode()) {
return new EventStream($response->getBody(), $serializer);
Expand Down
11 changes: 9 additions & 2 deletions tests/Stream/MultiJsonStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ public function testReadJsonEscapedDoubleQuote(string $jsonStream, array $jsonPa
$serializer = $this->getMockBuilder(SerializerInterface::class)
->getMock();

$callIndex = 0;
$serializer
->expects($this->exactly(\count($jsonParts)))
->method('deserialize')
->withConsecutive(...array_map(fn ($part) => [$part, BuildInfo::class, 'json', []], $jsonParts))
;
->willReturnCallback(function ($data, $class, $format, $context) use ($jsonParts, &$callIndex) {
$this->assertEquals($jsonParts[$callIndex], $data);
$this->assertEquals(BuildInfo::class, $class);
$this->assertEquals('json', $format);
$this->assertEquals([], $context);
$callIndex++;
return null;
});

$stub = $this->getMockForAbstractClass(MultiJsonStream::class, [$stream, $serializer]);
$stub->expects($this->any())
Expand Down