Skip to content

Commit

Permalink
Merge pull request #1481 from garak/remove-test-annotations
Browse files Browse the repository at this point in the history
🎨 remove annotations from tests
  • Loading branch information
garak authored Dec 2, 2024
2 parents 5bbfcb1 + 28e3156 commit adf48d9
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 64 deletions.
24 changes: 11 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,25 +16,23 @@ 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.).

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:
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile82
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile83
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 45 additions & 0 deletions docker/Dockerfile84
Original file line number Diff line number Diff line change
@@ -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"]
11 changes: 9 additions & 2 deletions tests/DependencyInjection/VichUploaderExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -172,6 +179,6 @@ public function testMetadataAttribute(): void
],
]);

self::assertContainerBuilderHasService('vich_uploader.metadata.reader', AttributeReader::class);
$this->assertContainerBuilderHasService('vich_uploader.metadata.reader', AttributeReader::class);
}
}
58 changes: 17 additions & 41 deletions tests/DummyFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
7 changes: 2 additions & 5 deletions tests/DummyImageFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
2 changes: 1 addition & 1 deletion tests/Fixtures/App/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ vich_uploader:
db_driver: orm

metadata:
type: annotation
type: attribute

mappings:
image_mapping:
Expand Down
6 changes: 6 additions & 0 deletions tests/Metadata/Driver/AnnotationDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* AnnotationDriverTest.
*
* @author Kévin Gomez <[email protected]>
*
* @group legacy
*/
final class AnnotationDriverTest extends TestCase
{
Expand All @@ -34,6 +36,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);

Expand Down

0 comments on commit adf48d9

Please sign in to comment.