Coder Social home page Coder Social logo

Comments (10)

magnetik avatar magnetik commented on May 27, 2024 1

Cannot confirm as I'm using sqlite cache & reference extensively.

Maybe you can share more code?

from liiptestfixturesbundle.

bropp avatar bropp commented on May 27, 2024 1

I also get this error when testing fixtures who have a composite primary key (multiple fields combined are the primary key).

i.e. (https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/tutorials/composite-primary-keys.html#use-case-3-join-table-with-metadata):

/** @Entity */ 
class OrderItem {     
/** @Id @ManyToOne(targetEntity="Order") */     
private $order;      

/** @Id @ManyToOne(targetEntity="Product") */     
private $product;     

 /** @Column(type="integer") */     
private $amount = 1;      

/** @Column(type="decimal") */     
private $offeredPrice;      

public function __construct(Order $order, Product $product, $amount = 1)     {         
    $this->order = $order;         
    $this->product = $product;        
    $this->offeredPrice = $product->getCurrentPrice();     
}
}

from liiptestfixturesbundle.

mtanasiewicz avatar mtanasiewicz commented on May 27, 2024 1

@alexislefebvre thank you for the answer! I will check tomorrow if this solves my problem.

from liiptestfixturesbundle.

tiberiu89 avatar tiberiu89 commented on May 27, 2024

Not much code to share. So I'm using standard doctrine fixtures for a symfony app, set some references in there(I'm using value objects and custom doctrine types if relevant) call ->persist() and then ->setReference(...)

Then in my tests, I have a base class web test case extending Liip\FunctionalTestBundle\Test\WebTestCase with the following setup(taken from the class)

    use FixturesTrait;

    /** @var KernelBrowser */
    protected $client;

    /** @var ReferenceRepository */
    protected static $fixtures;

    public static function setUpBeforeClass()
    {
        static::$fixtures = null;
    }

    public function setUp()
    {
        $this->client = $this->makeClient();

        // we load fixtures once per test suite so data is kept between tests
        // might as well work with `@depends`  annotations
        if (!static::$fixtures) {
            static::$fixtures = $this->loadFixtures([TestFixtures::class])
                ->getReferenceRepository();
        }
    }

I keep fxtures static there and try to instantiate it only once for each test case. Pretty much else is standard functional tests. The doctrine test config is

doctrine:
  dbal:
    driver: 'pdo_sqlite'
    path: '%kernel.cache_dir%/test.db'
    charset: utf8

Tests run fine as long as I use it without db cache, but once I add this to the config

liip_functional_test: ~
liip_test_fixtures:
  cache_db:
    sqlite: liip_test_fixtures.services_database_backup.sqlite

it will crash subsequent tests. I can see some files created in the cache directory(test_sqlite_somehash.db and .db.ser)

The error is as described above and it happens on this line
static::$fixtures = $this->loadFixtures([TestFixtures::class]), and by the looks of it, only when trying to recreate it from the cached db files

from liiptestfixturesbundle.

alexislefebvre avatar alexislefebvre commented on May 27, 2024

Please share the exception name. You only pasted the stack trace.

Anyway, if you use the cache you don't need to load the fixtures only once. So, try to load fixtures in setUp and tell us if the error is still present.

from liiptestfixturesbundle.

mtanasiewicz avatar mtanasiewicz commented on May 27, 2024

Same happens to me. Stack trace:

Array to string conversion
 /var/www/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:3036
 /var/www/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:491
 /var/www/symfony/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php:78
 /var/www/symfony/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php:105
 /var/www/symfony/vendor/liip/test-fixtures-bundle/src/Services/DatabaseBackup/SqliteDatabaseBackup.php:68
 /var/www/symfony/vendor/liip/test-fixtures-bundle/src/Services/DatabaseTools/ORMSqliteDatabaseTool.php:52
 /var/www/symfony/vendor/liip/test-fixtures-bundle/src/Test/FixturesTrait.php:87

from liiptestfixturesbundle.

mtanasiewicz avatar mtanasiewicz commented on May 27, 2024

I use postgreSql with id as UuidType, and those id's are being somehow lost on backup and restore of cache. When I load the fixtures with doctrine:fixtures:load --env=test where i have the sqlite driver configred it generates proper Uuid id's in the sqlite database file. When I debug the test exception with xdebug, I can see that in Doctrine\Common\DataFixtures\ProxyReferenceRepository::unserialize() the variable $serializedData comes with such values:

{"references":{"breakfast":["App\\Recipe\\Domain\\Entity\\Category",{"id":{}}],"main course":["App\\Recipe\\Domain\\Entity\\Category",{"id":{}}],"snack":["App\\Recipe\\Domain\\Entity\\Category",{"id":{}}],"ingredient_0":["App\\Recipe\\Domain\\Entity\\Ingredient",{"id":{}}],"ingredient_1":

This indicates that there might be some problem wtith id's during backup and restore of sqlite files or serialization.

from liiptestfixturesbundle.

alexislefebvre avatar alexislefebvre commented on May 27, 2024

Thanks for the information. The problem with uuid was also reported in liip/LiipFunctionalTestBundle#422 (comment)

We need to add a test with fixtures that use uuid.

from liiptestfixturesbundle.

mtanasiewicz avatar mtanasiewicz commented on May 27, 2024

@alexislefebvre Unfortunately changing Uuid generation to auto and setting proper metadata doesn't work at all. I still get the exception "array to string conversion"

from liiptestfixturesbundle.

mtanasiewicz avatar mtanasiewicz commented on May 27, 2024

Also when I try to implement my own Backup with \Liip\TestFixturesBundle\Services\DatabaseBackup\DatabaseBackupInterface and connect it according to docs, the library still doesn't use it. Completely nothing happens there as it falled back to default.

from liiptestfixturesbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.