diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 5984842aa92..8bad3494da8 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -5,29 +5,100 @@ on: pull_request: jobs: + static-analysis-phpstan: + name: "Static Analysis with PHPStan" + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.4" + + steps: + - name: "Checkout code" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + tools: "cs2pr" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v1" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Run a static analysis with phpstan/phpstan" + run: "vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr" + static-analysis-psalm: - name: Static Analysis with Psalm - runs-on: ubuntu-latest + name: "Static Analysis with Psalm" + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.4" + + steps: + - name: "Checkout code" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v1" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Run a static analysis with vimeo/psalm" + run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=4" + + coding-standards: + name: "Coding Standards" + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "7.4" steps: - - name: Checkout code - uses: actions/checkout@v2 + - name: "Checkout" + uses: "actions/checkout@v2" - name: "Install PHP" - uses: "shivammathur/setup-php@1.8.1" + uses: "shivammathur/setup-php@v2" with: coverage: "none" - php-version: "7.4" + php-version: "${{ matrix.php-version }}" + tools: "cs2pr" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v1.0.3" + uses: "actions/cache@v1" with: path: "~/.composer/cache" - key: "composer-${{ hashFiles('composer.lock') }}" - restore-keys: "composer-" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" - name: "Install dependencies with composer" run: "composer install --no-interaction --no-progress --no-suggest" - - name: Psalm - run: "vendor/bin/psalm" + - name: "Run squizlabs/php_codesniffer" + run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr" diff --git a/.travis.yml b/.travis.yml index 823fd073e72..4a421250895 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,16 +44,6 @@ jobs: - stage: Smoke Testing php: 7.3 env: DB=sqlite COVERAGE=yes - - stage: Smoke Testing - php: 7.3 - env: PHPStan - install: travis_retry composer install --prefer-dist - script: vendor/bin/phpstan analyse - - stage: Smoke Testing - php: 7.3 - env: PHP_CodeSniffer - install: travis_retry composer install --prefer-dist - script: vendor/bin/phpcs - stage: Test php: 7.2 diff --git a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php index cc15bc0f655..12f417119fc 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php @@ -55,7 +55,7 @@ public function acceptTable(Table $table) */ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) { - if (! $this->platform->supportsForeignKeyConstraints()) { + if (! $this->platform->supportsCreateDropForeignKeyConstraints()) { return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/ForeignKeyTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/ForeignKeyTest.php new file mode 100644 index 00000000000..7f86d8fc254 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/ForeignKeyTest.php @@ -0,0 +1,37 @@ +createTable('referenced_table'); + $referencedTable->addColumn('id', 'integer'); + $referencedTable->setPrimaryKey(['id']); + + $referencingTable = $schema->createTable('referencing_table'); + $referencingTable->addColumn('referenced_id', 'integer'); + $referencingTable->addForeignKeyConstraint( + $referencedTable, + ['referenced_id'], + ['id'] + ); + + foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) { + $this->connection->exec($sql); + } + + self::assertCount( + 1, + $this->connection->getSchemaManager()->listTableForeignKeys('referencing_table') + ); + } +} diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php index 1591cdcbad0..c60c2c41e71 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -29,7 +29,7 @@ protected function setUp() : void 'getCreateSchemaSQL', 'getCreateSequenceSQL', 'getCreateTableSQL', - 'supportsForeignKeyConstraints', + 'supportsCreateDropForeignKeyConstraints', 'supportsSchemas', ] ) @@ -76,11 +76,11 @@ public function testAcceptsTable() : void public function testAcceptsForeignKey() : void { $this->platformMock->expects($this->at(0)) - ->method('supportsForeignKeyConstraints') + ->method('supportsCreateDropForeignKeyConstraints') ->will($this->returnValue(false)); $this->platformMock->expects($this->at(1)) - ->method('supportsForeignKeyConstraints') + ->method('supportsCreateDropForeignKeyConstraints') ->will($this->returnValue(true)); $table = $this->createTableMock(); @@ -106,7 +106,7 @@ public function testAcceptsSequences() : void public function testResetsQueries() : void { - foreach (['supportsSchemas', 'supportsForeignKeyConstraints'] as $method) { + foreach (['supportsSchemas', 'supportsCreateDropForeignKeyConstraints'] as $method) { $this->platformMock->expects($this->any()) ->method($method) ->will($this->returnValue(true));