From 7bcb290791b5a35e522420a25848a208941d50a4 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Sun, 1 Dec 2024 10:49:23 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20remove=20annotations=20from=20te?= =?UTF-8?q?sts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CONTRIBUTING.md | 24 ++++---- docker/Dockerfile82 | 1 - docker/Dockerfile83 | 1 - docker/Dockerfile84 | 45 ++++++++++++++ .../VichUploaderExtensionTest.php | 11 +++- tests/DummyFile.php | 58 ++++++------------- tests/DummyImageFile.php | 7 +-- tests/Fixtures/App/app/config/config.yml | 2 +- .../Metadata/Driver/AnnotationDriverTest.php | 5 ++ 9 files changed, 90 insertions(+), 64 deletions(-) create mode 100644 docker/Dockerfile84 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9d2d5be4..8d2140e4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ First of all, **thank you** for contributing, **you are awesome**! -Here are a few rules to follow in order to ease code reviews, and discussions before +Here are a few rules to follow to facilitate code reviews and discussions before maintainers accept and merge your work. You MUST follow the [PSR-1](//www.php-fig.org/psr/psr-1/) and @@ -16,13 +16,11 @@ You MUST write (or update) unit tests. You SHOULD write documentation. -Please, write [commit messages that make -sense](//tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), +Please, write [commit messages that make sense](//tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), and [rebase your branch](//git-scm.com/book/en/v2/Git-Branching-Rebasing) before submitting your Pull Request. -One may ask you to [squash your -commits](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html) +One may ask you to [squash your commits](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html) too. This is used to "clean" your Pull Request before merging it (we don't want commits such as `fix tests`, `fix 2`, `fix 3`, etc.). @@ -30,11 +28,11 @@ Thank you! ## Running the test suite -Tests suite uses Docker environments in order to be idempotent to OS's. More than this -PHP version is written inside the Dockerfile; this assures to test the bundle with -the same resources. No need to have PHP or Mongo installed. +The test suite uses Docker environments to be idempotent to OS's. We use multiple +PHP versions in Docker, ensuring that the bundle is tested with +the same resources. There is no need to have PHP or Mongo installed. -You only need Docker set it up. +You only need Docker set up. To allow testing environments more smooth we implemented **Makefile**. You have two commands available: @@ -49,11 +47,11 @@ which will execute all tests inside the docker. make test TEST="Tests/Util/FilenameUtilsTest.php" ``` -will allow testing single Test Classes. +will allow testing single Test classes. -There are three environments available: PHP 8.1, PHP 8.2, and PHP 8.3. -Default environment is *PHP 8.1*. If you want to execute it against -other PHP versions, please use environment variables as this: +Four environments are available: PHP 8.1, PHP 8.2, PHP 8.3, and PHP 8.4. +The default environment is *PHP 8.1*. If you want to execute tests against +other PHP versions, please use the environment variables as this: ```bash make tests #PHP 8.1 env diff --git a/docker/Dockerfile82 b/docker/Dockerfile82 index 8a2e8062..77556e3c 100644 --- a/docker/Dockerfile82 +++ b/docker/Dockerfile82 @@ -39,7 +39,6 @@ COPY . ./ RUN set -eux; \ sed -i 's/"league\/flysystem": "<2.0"/"league\/flysystem": "<2.0", "symfony\/http-kernel": "6.0.*,>6.4.8 || 7.1.*,>7.1.1"/' composer.json; \ - composer require --no-update doctrine/annotations:^1.14; \ composer update --prefer-dist --ignore-platform-reqs; \ composer clear-cache diff --git a/docker/Dockerfile83 b/docker/Dockerfile83 index bde9eda4..b6202788 100644 --- a/docker/Dockerfile83 +++ b/docker/Dockerfile83 @@ -39,7 +39,6 @@ COPY . ./ RUN set -eux; \ sed -i 's/"league\/flysystem": "<2.0"/"league\/flysystem": "<2.0", "symfony\/http-kernel": "6.0.*,>6.4.8 || 7.1.*,>7.1.1"/' composer.json; \ - composer require --no-update doctrine/annotations:^1.14; \ composer update --prefer-dist --ignore-platform-reqs; \ composer clear-cache diff --git a/docker/Dockerfile84 b/docker/Dockerfile84 new file mode 100644 index 00000000..aca9289b --- /dev/null +++ b/docker/Dockerfile84 @@ -0,0 +1,45 @@ +FROM php:8.4-alpine + +ARG MONGODB_VERSION=1.20.0 + +# Install mongo +RUN set -eux; \ + apk add --no-cache --virtual .build-deps \ + $PHPIZE_DEPS \ + openssl-dev \ + ; \ + pecl install \ + mongodb-${MONGODB_VERSION} \ + ; \ + docker-php-ext-enable \ + mongodb \ + ; \ + pecl clear-cache; \ + \ + runDeps="$( \ + scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \ + | tr ',' '\n' \ + | sort -u \ + | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ + )"; \ + apk add --no-cache --virtual .api-add-phpexts-rundeps $runDeps \ + curl \ + ; + +RUN curl -s https://getcomposer.org/installer | php + +RUN mv composer.phar /usr/local/bin/composer + +WORKDIR /srv/vich-uploader + +# prevent the reinstallation of vendors at every changes in the source code + +#COPY ./docker/script/runTests.sh ./runTests.sh +COPY . ./ + +RUN set -eux; \ + sed -i 's/"league\/flysystem": "<2.0"/"league\/flysystem": "<2.0", "symfony\/http-kernel": "6.0.*,>6.4.8 || 7.1.*,>7.1.1"/' composer.json; \ + composer update --prefer-dist --ignore-platform-reqs; \ + composer clear-cache + +CMD ["/init"] diff --git a/tests/DependencyInjection/VichUploaderExtensionTest.php b/tests/DependencyInjection/VichUploaderExtensionTest.php index bdac3f3d..bd58cc27 100644 --- a/tests/DependencyInjection/VichUploaderExtensionTest.php +++ b/tests/DependencyInjection/VichUploaderExtensionTest.php @@ -153,15 +153,22 @@ public function testFormThemeCorrectlyOverridden(): void ); } + /** + * @group legacy + */ public function testMetadataAnnotation(): void { + if (!class_exists(AnnotationReader::class)) { + $this->markTestSkipped('The doctrine/annotations package is not installed'); + } + $this->load([ 'metadata' => [ 'type' => 'annotation', ], ]); - self::assertContainerBuilderHasService('vich_uploader.metadata.reader', AnnotationReader::class); + $this->assertContainerBuilderHasService('vich_uploader.metadata.reader', AnnotationReader::class); } public function testMetadataAttribute(): void @@ -172,6 +179,6 @@ public function testMetadataAttribute(): void ], ]); - self::assertContainerBuilderHasService('vich_uploader.metadata.reader', AttributeReader::class); + $this->assertContainerBuilderHasService('vich_uploader.metadata.reader', AttributeReader::class); } } diff --git a/tests/DummyFile.php b/tests/DummyFile.php index 991a4dfb..5f96118c 100644 --- a/tests/DummyFile.php +++ b/tests/DummyFile.php @@ -6,49 +6,25 @@ use Symfony\Component\HttpFoundation\File\File as SymfonyFile; use Vich\UploaderBundle\Mapping\Annotation as Vich; -/** - * @Vich\Uploadable - */ +#[Vich\Uploadable] class DummyFile { - /** - * @ORM\Id - * - * @ORM\Column(type="integer") - * - * @ORM\GeneratedValue(strategy="AUTO") - * - * @var int - */ - protected $id; - - /** - * @ORM\Column(type="string") - * - * @var string - */ - protected $title; - - /** - * @ORM\Column(type="datetime") - * - * @var \DateTime - */ - protected $updatedAt; - - /** - * @Vich\UploadableField(mapping="image_mapping", fileNameProperty="imageName") - * - * @var SymfonyFile - */ - protected $file; - - /** - * @ORM\Column(type="string", nullable=true) - * - * @var string - */ - protected $fileName; + #[ORM\Id] + #[ORM\Column] + #[ORM\GeneratedValue] + protected ?int $id = null; + + #[ORM\Column] + protected ?string $title = null; + + #[ORM\Column(nullable: true)] + protected ?\DateTime $updatedAt = null; + + #[Vich\UploadableField(mapping: "image_mapping", fileNameProperty: "imageName")] + protected ?SymfonyFile $file = null; + + #[ORM\Column(nullable: true)] + protected ?string $fileName = null; public function getId(): ?int { diff --git a/tests/DummyImageFile.php b/tests/DummyImageFile.php index 129541aa..1be16d81 100644 --- a/tests/DummyImageFile.php +++ b/tests/DummyImageFile.php @@ -5,11 +5,8 @@ use Doctrine\ORM\Mapping as ORM; use Vich\UploaderBundle\Mapping\Annotation as Vich; -/** - * @ORM\Entity - * - * @Vich\Uploadable - */ +#[ORM\Entity] +#[Vich\Uploadable] class DummyImageFile { } diff --git a/tests/Fixtures/App/app/config/config.yml b/tests/Fixtures/App/app/config/config.yml index d6d05ed5..f7c200d2 100644 --- a/tests/Fixtures/App/app/config/config.yml +++ b/tests/Fixtures/App/app/config/config.yml @@ -46,7 +46,7 @@ vich_uploader: db_driver: orm metadata: - type: annotation + type: attribute mappings: image_mapping: diff --git a/tests/Metadata/Driver/AnnotationDriverTest.php b/tests/Metadata/Driver/AnnotationDriverTest.php index aef4d983..11bb5a83 100644 --- a/tests/Metadata/Driver/AnnotationDriverTest.php +++ b/tests/Metadata/Driver/AnnotationDriverTest.php @@ -21,6 +21,7 @@ * AnnotationDriverTest. * * @author Kévin Gomez + * @group legacy */ final class AnnotationDriverTest extends TestCase { @@ -34,6 +35,10 @@ final class AnnotationDriverTest extends TestCase protected function setUp(): void { + if (!class_exists(Reader::class)) { + $this->markTestSkipped('The doctrine/annotations package is not installed'); + } + // setup ManagerRegistry mock like Symfony\Bridge\Doctrine tests $this->connection = $this->createMock(Connection::class);