Fix test failures: correct API usage and mock returns #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [master, main] | |
| pull_request: | |
| branches: [master, main] | |
| permissions: | |
| contents: read | |
| jobs: | |
| test: | |
| name: PHP ${{ matrix.php }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| php: ['8.1', '8.2', '8.3', '8.4'] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| coverage: none | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-progress | |
| - name: Run tests | |
| run: vendor/bin/phpunit --colors=always | |
| coverage: | |
| name: Code Coverage | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.3' | |
| coverage: pcov | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-progress | |
| - name: Run tests with coverage | |
| run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| files: coverage.xml | |
| flags: unittests | |
| name: mcp-tool-gateway | |
| fail_ci_if_error: false | |
| env: | |
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
| static-analysis: | |
| name: Static Analysis | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.3' | |
| coverage: none | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-progress | |
| - name: Run PHPStan | |
| run: vendor/bin/phpstan analyse src --level=8 | |
| integration: | |
| name: Integration Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.3' | |
| coverage: none | |
| - name: Install dependencies with optional packages | |
| run: | | |
| composer require code-wheel/mcp-schema-builder:^1.1 code-wheel/mcp-error-codes:^1.2 --no-interaction | |
| composer install --prefer-dist --no-progress | |
| - name: Test ValidatingMiddleware integration | |
| run: | | |
| php -r " | |
| require 'vendor/autoload.php'; | |
| use CodeWheel\McpToolGateway\ArrayToolProvider; | |
| use CodeWheel\McpToolGateway\ToolInfo; | |
| use CodeWheel\McpToolGateway\ToolResult; | |
| use CodeWheel\McpToolGateway\Middleware\MiddlewarePipeline; | |
| use CodeWheel\McpToolGateway\Middleware\ValidatingMiddleware; | |
| use CodeWheel\McpToolGateway\Validation\ValidatorInterface; | |
| use CodeWheel\McpToolGateway\Validation\ValidationResultInterface; | |
| use CodeWheel\McpToolGateway\Validation\ValidationErrorInterface; | |
| use CodeWheel\McpSchemaBuilder\SchemaValidator; | |
| use CodeWheel\McpSchemaBuilder\ValidationResult; | |
| use CodeWheel\McpSchemaBuilder\ValidationError; | |
| // Adapter to wrap SchemaValidator | |
| class SchemaValidatorAdapter implements ValidatorInterface { | |
| public function validate(array \$data, array \$schema): ValidationResultInterface { | |
| \$validator = new SchemaValidator(\$schema); | |
| \$result = \$validator->validate(\$data); | |
| return new class(\$result) implements ValidationResultInterface { | |
| public function __construct(private ValidationResult \$result) {} | |
| public function isValid(): bool { return \$this->result->isValid(); } | |
| public function getErrors(): array { | |
| return array_map(fn(\$e) => new class(\$e) implements ValidationErrorInterface { | |
| public function __construct(private ValidationError \$error) {} | |
| public function getPath(): string { return \$this->error->path; } | |
| public function getMessage(): string { return \$this->error->message; } | |
| public function getCode(): string { return \$this->error->constraint; } | |
| }, \$this->result->getErrors()); | |
| } | |
| }; | |
| } | |
| } | |
| \$provider = new ArrayToolProvider([ | |
| 'test' => new ToolInfo( | |
| name: 'test', | |
| label: 'Test', | |
| description: 'Test tool', | |
| inputSchema: [ | |
| 'type' => 'object', | |
| 'properties' => ['name' => ['type' => 'string']], | |
| 'required' => ['name'], | |
| ], | |
| ), | |
| ]); | |
| \$provider->setHandler('test', fn(\$args) => ToolResult::success('OK')); | |
| \$validator = new SchemaValidatorAdapter(); | |
| \$middleware = new ValidatingMiddleware(\$provider, \$validator); | |
| \$pipeline = new MiddlewarePipeline(\$provider); | |
| \$pipeline->add(\$middleware); | |
| // Test with missing required field | |
| \$result = \$pipeline->execute('test', []); | |
| if (\$result->success) { | |
| echo 'FAIL: Should reject missing required field'; | |
| exit(1); | |
| } | |
| // Test with valid input | |
| \$result = \$pipeline->execute('test', ['name' => 'John']); | |
| if (!\$result->success) { | |
| echo 'FAIL: Should accept valid input'; | |
| exit(1); | |
| } | |
| echo 'Integration test passed!'; | |
| " |