Skip to content

Commit

Permalink
Allow symfony/var-exporter:^7
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Jan 19, 2024
1 parent ea0bd9f commit a949c22
Show file tree
Hide file tree
Showing 64 changed files with 181 additions and 400 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## v0.31.0

### Fixed

- Allow `symfony/var-exporter:^7`

## v0.30.1

### Fixed
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,10 @@ Otherwise, mocks are not reset between test methods, you might run into very con
Mocks are registered per operation class:

```php
/** @var \Mockery\MockInterface&\Example\Api\Operations\HelloSailor */
$mock = \Example\Api\Operations\HelloSailor::mock();
use Example\Api\Operations\HelloSailor;

/** @var \Mockery\MockInterface&HelloSailor */
$mock = HelloSailor::mock();
```

When registered, the mock captures all calls to `HelloSailor::execute()`.
Expand All @@ -405,7 +407,7 @@ $mock
->expects('execute')
->once()
->with('Sailor')
->andReturn(HelloSailorResult::fromData(
->andReturn(HelloSailor\HelloSailorResult::fromData(
HelloSailor\HelloSailor::make($hello),
));

Expand All @@ -425,7 +427,7 @@ assert($mock1 === $mock2); // true
You can also simulate a result with errors:

```php
HelloSailorResult::fromErrors([
HelloSailor\HelloSailorResult::fromErrors([
(object) [
'message' => 'Something went wrong',
],
Expand All @@ -435,13 +437,13 @@ HelloSailorResult::fromErrors([
For PHP 8 users, it is recommended to use named arguments to build complex mocked results:

```php
HelloSailorResult::fromData(
HelloSailor::make(
HelloSailor\HelloSailorResult::fromData(
HelloSailor\HelloSailor::make(
hello: 'Hello, Sailor!',
nested: HelloSailor\Nested::make(
nested: HelloSailor\HelloSailor\Nested::make(
hello: 'Hello again!',
)
)
),
),
))
```

Expand Down
12 changes: 3 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"nette/php-generator": "^3.6.7 || ^4",
"psr/http-client": "^1",
"symfony/console": "^5 || ^6 || ^7",
"symfony/var-exporter": "^5.3 || ^6",
"symfony/var-exporter": "^5.3 || ^6 || ^7",
"thecodingmachine/safe": "^1 || ^2",
"webonyx/graphql-php": "^14.11.3 || ^15"
},
Expand All @@ -31,7 +31,7 @@
"guzzlehttp/guzzle": "^7",
"infection/infection": "~0.21",
"jangregor/phpstan-prophecy": "^1",
"mll-lab/php-cs-fixer-config": "^4.3",
"mll-lab/php-cs-fixer-config": "^5",
"mockery/mockery": "^1.4",
"nyholm/psr7": "^1.4",
"php-http/httplug": "^2",
Expand All @@ -43,7 +43,7 @@
"phpstan/phpstan-phpunit": "^1",
"phpstan/phpstan-strict-rules": "^1",
"phpunit/phpunit": "^9.5.2",
"spawnia/phpunit-assert-directory": "dev-php8 as 3.0.0",
"spawnia/phpunit-assert-directory": "^2",
"symfony/var-dumper": "^5.2.3",
"thecodingmachine/phpstan-safe-rule": "^1.1"
},
Expand All @@ -52,12 +52,6 @@
"guzzlehttp/guzzle": "Enables using the built-in default Client",
"mockery/mockery": "Used in Operation::mock()"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/simpod/phpunit-assert-directory"
}
],
"autoload": {
"psr-4": {
"Spawnia\\Sailor\\": "src/"
Expand Down
8 changes: 2 additions & 6 deletions examples/custom-types/src/CustomObjectTypeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ final class CustomObjectTypeConfig implements TypeConfig, InputTypeConfig, Outpu

private EndpointConfig $endpointConfig;

/**
* @var Type&NamedType
*/
/** @var Type&NamedType */
private Type $type;

/**
* @param Type&NamedType $type
*/
/** @param Type&NamedType $type */
public function __construct(EndpointConfig $endpointConfig, Type $type)
{
$this->endpointConfig = $endpointConfig;
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-types/src/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$myCustomEnumQueryResult = MyCustomEnumQuery::execute(
new CustomEnum(CustomEnum::A)
);
assert(CustomEnum::B === $myCustomEnumQueryResult->data->withCustomEnum->value);
assert($myCustomEnumQueryResult->data->withCustomEnum->value === CustomEnum::B);

$foo = 'foo';
$myCustomObjectQueryResult = MyCustomObjectQuery::execute(
Expand Down
4 changes: 2 additions & 2 deletions examples/input/src/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

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

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

assert(42 === $result->data->takeSomeInput);
assert($result->data->takeSomeInput === 42);
6 changes: 3 additions & 3 deletions examples/php-keywords/src/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
$switch = $result->data->print;
assert($switch instanceof _Switch);

assert(_abstract::_class === $switch->for);
assert(42 === $switch->int);
assert(69 === $switch->as);
assert($switch->for === _abstract::_class);
assert($switch->int === 42);
assert($switch->as === 69);
2 changes: 1 addition & 1 deletion examples/polymorphic/src/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

assert($userOrPost instanceof UserOrPost\Node\User);
assert($userOrPost->id === $id);
assert('blarg' === $userOrPost->name);
assert($userOrPost->name === 'blarg');
4 changes: 2 additions & 2 deletions examples/simple/src/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

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

$result = \Spawnia\Sailor\Simple\Operations\MyObjectQuery::execute();
$result = Spawnia\Sailor\Simple\Operations\MyObjectQuery::execute();

assert(42 === $result->data->singleObject->value);
assert($result->data->singleObject->value === 42);
18 changes: 5 additions & 13 deletions sailor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public function makeClient(): Spawnia\Sailor\Client
{
return new \Spawnia\Sailor\Client\Guzzle(
return new Spawnia\Sailor\Client\Guzzle(
'https://example.com/graphql',
[
'headers' => [
Expand All @@ -29,33 +29,25 @@ public function makeClient(): Spawnia\Sailor\Client
);
}

/**
* The namespace the generated classes will be created in.
*/
/** The namespace the generated classes will be created in. */
public function namespace(): string
{
return 'Vendor\\ExampleApi';
}

/**
* Path to the directory where the generated classes will be put.
*/
/** Path to the directory where the generated classes will be put. */
public function targetPath(): string
{
return __DIR__ . '/generated/ExampleApi';
}

/**
* Where to look for .graphql files containing operations.
*/
/** Where to look for .graphql files containing operations. */
public function searchPath(): string
{
return __DIR__ . '/src';
}

/**
* The location of the schema file that describes the endpoint.
*/
/** The location of the schema file that describes the endpoint. */
public function schemaPath(): string
{
return __DIR__ . '/example.graphql';
Expand Down
8 changes: 2 additions & 6 deletions src/BelongsToEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

interface BelongsToEndpoint
{
/**
* Path to the config file of the endpoint.
*/
/** Path to the config file of the endpoint. */
public static function config(): string;

/**
* Name of the endpoint this class belongs to.
*/
/** Name of the endpoint this class belongs to. */
public static function endpoint(): string;
}
4 changes: 1 addition & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

interface Client
{
/**
* Execute a GraphQL query against an endpoint and return a Response.
*/
/** Execute a GraphQL query against an endpoint and return a Response. */
public function request(string $query, \stdClass $variables = null): Response;
}
4 changes: 1 addition & 3 deletions src/Client/Guzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class Guzzle implements Client

protected GuzzleClient $guzzle;

/**
* @param array<string, mixed> $config
*/
/** @param array<string, mixed> $config */
public function __construct(string $uri, array $config = [])
{
$this->uri = $uri;
Expand Down
4 changes: 2 additions & 2 deletions src/Codegen/AddTypename.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ protected static function purgeRedundant(SelectionSetNode $selectionSetNode): vo

foreach ($selections as $i => $selection) {
if ($selection instanceof FieldNode) {
if (Introspection::TYPE_NAME_FIELD_NAME === $selection->name->value) {
if ($selection->name->value === Introspection::TYPE_NAME_FIELD_NAME) {
unset($selections[$i]);
}

$subSelectionSet = $selection->selectionSet;
if (null !== $subSelectionSet) {
if ($subSelectionSet !== null) {
static::ensurePresent($subSelectionSet);
}
} elseif ($selection instanceof InlineFragmentNode) {
Expand Down
4 changes: 1 addition & 3 deletions src/Codegen/ClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

interface ClassGenerator
{
/**
* @return iterable<ClassType>
*/
/** @return iterable<ClassType> */
public function generate(): iterable;
}
2 changes: 1 addition & 1 deletion src/Codegen/DirectoryFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function documents(): array

// When installing from source, the examples might end up in the critical path,
// so we exclude them from the search.
if (false !== mb_strpos($path, 'vendor/spawnia/sailor/')) {
if (mb_strpos($path, 'vendor/spawnia/sailor/') !== false) {
continue;
}

Expand Down
4 changes: 1 addition & 3 deletions src/Codegen/EnumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public function __construct(EndpointConfig $endpointConfig, EnumType $enumType)
$this->enumType = $enumType;
}

/**
* @return iterable<ClassType>
*/
/** @return iterable<ClassType> */
public function generate(): iterable
{
$class = $this->makeClass();
Expand Down
6 changes: 2 additions & 4 deletions src/Codegen/Escaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ public static function escapeClassName(string $name): string
: $name;
}

/**
* TODO remove with PHP 8.
*/
/** TODO remove with PHP 8. */
public static function escapeNamespaceName(string $name): string
{
return static::escapeClassName($name);
}

public static function escapeMemberConstantName(string $name): string
{
return 'class' === \strtolower($name)
return \strtolower($name) === 'class'
? "_{$name}"
: $name;
}
Expand Down
12 changes: 3 additions & 9 deletions src/Codegen/FoldFragments.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ class FoldFragments
{
protected DocumentNode $document;

/**
* @var array<string, OperationDefinitionNode>
*/
/** @var array<string, OperationDefinitionNode> */
protected array $operations = [];

/**
* @var array<string, FragmentDefinitionNode>
*/
/** @var array<string, FragmentDefinitionNode> */
protected array $fragments = [];

public function __construct(DocumentNode $document)
Expand Down Expand Up @@ -61,9 +57,7 @@ public function modify(): DocumentNode
]);
}

/**
* @return NodeList<Node&SelectionNode>
*/
/** @return NodeList<Node&SelectionNode> */
protected function extractFields(SelectionSetNode $selectionSet): NodeList
{
/** @var array<int, Node&SelectionNode> $selections */
Expand Down
Loading

0 comments on commit a949c22

Please sign in to comment.