Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Поправил некоторые ошибки в функциональных тестах #21

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ENV_LOCAL := $(PWD)/.env.local
include $(ENV)
-include $(ENV_LOCAL)


default:
@echo "make needs target:"
@egrep -e '^\S+' ./Makefile | grep -v default | sed -r 's/://' | sed -r 's/^/ - /'
Expand Down Expand Up @@ -96,10 +97,15 @@ test-run-functional: debug-print-env
docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:drop --force
docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:create
docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:update --dump-sql
docker-compose run --rm php-cli php vendor/bin/phpunit --testsuite=functional_tests --display-warnings --testdox
docker-compose run --rm php-cli php -dxdebug.start_with_request=yes vendor/bin/phpunit --testsuite=functional_tests --display-warnings --testdox

# Запустить один функциональный тест с дебагером
run-one-functional-test: debug-print-env
docker-compose run --rm php-cli php -dxdebug.start_with_request=yes vendor/bin/phpunit --filter 'testFindByApplicationToken' tests/Functional/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepositoryTest.php

schema-drop:
docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:drop --force

schema-create:
docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:create
docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:create

4 changes: 4 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ services:
- database
volumes:
- .:/var/www/html
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
PHP_IDE_CONFIG: "serverName=docker-cli"
working_dir: /var/www/html
database:
image: postgres:${POSTGRES_VERSION:-16}-alpine
Expand Down
12 changes: 10 additions & 2 deletions docker/php-cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
FROM php:8.3-cli-alpine

RUN apk add unzip libpq-dev git icu-dev \
RUN apk add unzip libpq-dev git icu-dev autoconf build-base linux-headers \
&& docker-php-ext-install bcmath pdo pdo_pgsql intl \
&& docker-php-ext-enable bcmath pdo pdo_pgsql intl

RUN pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host = host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_port = 9003" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

RUN git config --global --add safe.directory /var/www/html

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer --quiet

ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_ALLOW_SUPERUSER=1
87 changes: 48 additions & 39 deletions tests/EntityManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\OptimisticLockException;
use Monolog\Logger;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\ORMSetup;
use Doctrine\DBAL\Types\Type;


use Monolog\Handler\StreamHandler;
use Monolog\Level;
class EntityManagerFactory
{
/**
Expand All @@ -26,54 +27,62 @@ class EntityManagerFactory
* @throws ORMException
* @throws Exception
*/

private static ?EntityManager $entityManager = null;

public static function get(): EntityManagerInterface
{
/* $paths = [
dirname(__DIR__) . '/src/Bitrix24Accounts/Entity'
];*/
$paths = [
dirname(__DIR__) . '/config/xml'
];
$isDevMode = true;

if (!array_key_exists('DATABASE_HOST', $_ENV)) {
throw new WrongConfigurationException('DATABASE_HOST not defined in $_ENV');
}
if (self::$entityManager === null) {
$paths = [
dirname(__DIR__) . '/config/xml'
];
$isDevMode = true;

if (!array_key_exists('DATABASE_USER', $_ENV)) {
throw new WrongConfigurationException('DATABASE_USER not defined in $_ENV');
}
if (!array_key_exists('DATABASE_HOST', $_ENV)) {
throw new WrongConfigurationException('DATABASE_HOST not defined in $_ENV');
}

if (!array_key_exists('DATABASE_PASSWORD', $_ENV)) {
throw new WrongConfigurationException('DATABASE_PASSWORD not defined in $_ENV');
}
if (!array_key_exists('DATABASE_USER', $_ENV)) {
throw new WrongConfigurationException('DATABASE_USER not defined in $_ENV');
}

if (!array_key_exists('DATABASE_NAME', $_ENV)) {
throw new WrongConfigurationException('DATABASE_NAME not defined in $_ENV');
}
if (!array_key_exists('DATABASE_PASSWORD', $_ENV)) {
throw new WrongConfigurationException('DATABASE_PASSWORD not defined in $_ENV');
}

$connectionParams = [
'driver' => 'pdo_pgsql',
'host' => $_ENV['DATABASE_HOST'],
'user' => $_ENV['DATABASE_USER'],
'password' => $_ENV['DATABASE_PASSWORD'],
'dbname' => $_ENV['DATABASE_NAME'],
];
if (!Type::hasType(UuidType::NAME)) {
Type::addType(UuidType::NAME, UuidType::class);
}
if (!array_key_exists('DATABASE_NAME', $_ENV)) {
throw new WrongConfigurationException('DATABASE_NAME not defined in $_ENV');
}

if (!Type::hasType('carbon_immutable')) {
Type::addType('carbon_immutable', CarbonImmutableType::class);
}
$connectionParams = [
'driver' => 'pdo_pgsql',
'host' => $_ENV['DATABASE_HOST'],
'user' => $_ENV['DATABASE_USER'],
'password' => $_ENV['DATABASE_PASSWORD'],
'dbname' => $_ENV['DATABASE_NAME'],
];

if (!Type::hasType(UuidType::NAME)) {
Type::addType(UuidType::NAME, UuidType::class);
}

// $configuration = ORMSetup::createAttributeMetadataConfiguration($paths, $isDevMode);
$configuration = ORMSetup::createXMLMetadataConfiguration($paths, $isDevMode);
$connection = DriverManager::getConnection($connectionParams, $configuration);
$entityManager = new EntityManager($connection, $configuration);
// todo разобраться, почему так, без этого объекты оставались в кеше и при find мы получали старые значения
$entityManager->clear();
$entityManager->flush();
return $entityManager;
if (!Type::hasType('carbon_immutable')) {
Type::addType('carbon_immutable', CarbonImmutableType::class);
}

// $configuration = ORMSetup::createAttributeMetadataConfiguration($paths, $isDevMode);
$configuration = ORMSetup::createXMLMetadataConfiguration($paths, $isDevMode);
// $log = new Logger('name');
// $log->pushHandler(new StreamHandler('log.txt', Level::Debug));

// $configuration->setMiddlewares([new \Doctrine\DBAL\Logging\Middleware($log)]);
$connection = DriverManager::getConnection($connectionParams, $configuration);
self::$entityManager = new EntityManager($connection, $configuration);
}
return self::$entityManager;
}
}
Loading