Skip to content

Commit

Permalink
Cover additional PHP keyword edge cases (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia authored Jul 7, 2022
1 parent 5671f01 commit a7ad8a9
Show file tree
Hide file tree
Showing 48 changed files with 522 additions and 549 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ jobs:
strategy:
matrix:
example:
- custom-types
- input
- install
- php-keywords
- simple
- polymorphic

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Add support for types and fields named equivalent to PHP keywords like `type Switch` or `{ print { subfield } }`.

### Removed

- No longer generate class `TypeConverters`

## v0.21.2

### Fixed
Expand Down
28 changes: 12 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: it
it: fix stan test ## Run the commonly used targets
it: fix stan approve test test-examples ## Run the commonly used targets

.PHONY: help
help: ## Displays this list of targets with descriptions
Expand All @@ -14,11 +14,6 @@ stan: ## Runs static analysis with phpstan
mkdir -p .build/phpstan
vendor/bin/phpstan analyse --configuration=phpstan.neon

.PHONY: codegen
codegen: ## Runs the codegen tests
mkdir -p .build/phpunit
vendor/bin/phpunit --filter CodegenTest

.PHONY: test
test: ## Runs tests with phpunit
mkdir -p .build/phpunit
Expand All @@ -35,17 +30,18 @@ infection: ## Runs mutation tests with infection
mkdir -p .build/infection
vendor/bin/infection --ignore-msi-with-no-mutations --min-covered-msi=100 --min-msi=100

define approve_example
rm -rf examples/$(1)/expected
cp -r examples/$(1)/generated examples/$(1)/expected
endef

.PHONY: approve
approve: ## Accept the current generated code as expected
$(call approve_example,custom-types)
$(call approve_example,input)
$(call approve_example,polymorphic)
$(call approve_example,simple)
approve: ## Generate code and approve it as expected
tests/generate-and-approve-examples.php

.PHONY: test-examples
test-examples: ## Test examples
cd examples/custom-types && ./test.sh
cd examples/input && ./test.sh
cd examples/install && ./test.sh
cd examples/php-keywords && ./test.sh
cd examples/polymorphic && ./test.sh
cd examples/simple && ./test.sh

vendor: composer.json composer.lock
composer install
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"Spawnia\\Sailor\\CustomTypesSrc\\": "examples/custom-types/src/",
"Spawnia\\Sailor\\Input\\": "examples/input/expected/",
"Spawnia\\Sailor\\Simple\\": "examples/simple/expected/",
"Spawnia\\Sailor\\PhpKeywords\\": "examples/php-keywords/expected/",
"Spawnia\\Sailor\\Polymorphic\\": "examples/polymorphic/expected/"
},
"files": [
Expand Down
109 changes: 0 additions & 109 deletions examples/custom-types/expected/TypeConverters.php

This file was deleted.

6 changes: 2 additions & 4 deletions examples/custom-types/sailor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use GraphQL\Type\Schema;
use Spawnia\Sailor\Client;
use Spawnia\Sailor\CustomTypes\Types\CustomEnum;
use Spawnia\Sailor\CustomTypesSrc\CustomDateTypeConfig;
use Spawnia\Sailor\CustomTypesSrc\CustomEnumTypeConfig;
use Spawnia\Sailor\EndpointConfig;
Expand Down Expand Up @@ -39,10 +40,7 @@ public function makeClient(): Client
return Response::fromStdClass((object) [
'data' => (object) [
'__typename' => 'Query',
'singleObject' => (object) [
'__typename' => 'SomeObject',
'value' => 42,
],
'withCustomEnum' => CustomEnum::B,
],
]);
};
Expand Down
9 changes: 7 additions & 2 deletions examples/custom-types/src/test.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php declare(strict_types=1);

use Spawnia\Sailor\CustomTypes\Operations\MyCustomEnumQuery;
use Spawnia\Sailor\CustomTypes\Types\CustomEnum;

require __DIR__ . '/../vendor/autoload.php';

$result = \Spawnia\Sailor\Simple\Operations\MyObjectQuery::execute();
$result = MyCustomEnumQuery::execute(
new CustomEnum(CustomEnum::A)
);

assert(42 === $result->data->singleObject->value);
assert(CustomEnum::B === $result->data->withCustomEnum->value);
Empty file modified examples/custom-types/test.sh
100644 → 100755
Empty file.
74 changes: 0 additions & 74 deletions examples/input/expected/TypeConverters.php

This file was deleted.

7 changes: 2 additions & 5 deletions examples/input/sailor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ public function makeClient(): Client
$mockClient->responseMocks[] = static function (): Response {
return Response::fromStdClass((object) [
'data' => (object) [
'__typename' => 'Query',
'singleObject' => (object) [
'__typename' => 'SomeObject',
'value' => 42,
],
'__typename' => 'Mutation',
'takeSomeInput' => 42,
],
]);
};
Expand Down
2 changes: 1 addition & 1 deletion examples/input/src/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

$result = \Spawnia\Sailor\Input\Operations\TakeSomeInput::execute();

assert(42 === $result->data->singleObject->value);
assert(42 === $result->data->takeSomeInput);
Empty file modified examples/input/test.sh
100644 → 100755
Empty file.
3 changes: 3 additions & 0 deletions examples/install/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ set -euxo pipefail

composer update

echo Clean up previous runs
rm -f sailor.php

if vendor/bin/sailor; then
echo Expected the initial run of vendor/bin/sailor to exit with an error
exit 1;
Expand Down
4 changes: 4 additions & 0 deletions examples/php-keywords/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/sailor
/vendor
/composer.lock
/generated
24 changes: 24 additions & 0 deletions examples/php-keywords/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"require": {
"spawnia/sailor": "@dev"
},
"autoload": {
"psr-4": {
"Spawnia\\Sailor\\PhpKeywords\\": "generated/"
}
},
"repositories": [
{
"type": "path",
"url": "./sailor",
"options": {
"symlink": false
}
}
],
"scripts": {
"move-package": "rsync -r ../../ sailor --exclude examples --exclude vendor --exclude .idea --exclude .build --delete",
"pre-install-cmd": "@move-package",
"pre-update-cmd": "@move-package"
}
}
Loading

0 comments on commit a7ad8a9

Please sign in to comment.