public function persist(PackageVersion $packageVersion) { if (null === ($packageVersionId = $packageVersion->getId())) { throw new \InvalidArgumentException('The $packageVersion must already have been persisted to the database.'); } // We are ensuring that all inserts are executed within a transaction. // See: http://dev.mysql.com/doc/refman/5.5/en/optimizing-innodb-bulk-data-loading.html $this->con->beginTransaction(); try { foreach ($packageVersion->getContainers() as $container) { $this->containerPersister->persist($container, $packageVersionId); } foreach ($packageVersion->getFunctions() as $function) { $this->functionPersister->persist($function, $packageVersionId); } foreach ($packageVersion->getConstants() as $constant) { $this->constantPersister->persist($constant, $packageVersionId); } $this->con->commit(); } catch (\Exception $ex) { $this->con->rollBack(); throw $ex; } }
protected function setUp() { if (!isset($_SERVER['MYSQL_USER']) || !isset($_SERVER['MYSQL_HOST']) || !isset($_SERVER['MYSQL_PASSWORD']) || !isset($_SERVER['MYSQL_DATABASE'])) { $this->markTestSkipped('You need to configure a MySQL database, see phpunit.dist.xml'); } $this->em = TestUtils::createMysqlTestEntityManager($_SERVER['MYSQL_USER'], $_SERVER['MYSQL_PASSWORD'], $_SERVER['MYSQL_DATABASE'], $_SERVER['MYSQL_HOST']); $this->repo = $this->em->getRepository('Scrutinizer\\PhpAnalyzer\\Model\\Package'); $this->typeProvider = new EntityTypeProvider($this->em); $this->typeRegistry = new TypeRegistry($this->typeProvider); $this->package = new Package('foo'); $this->packageVersion = $this->package->createVersion('1.0'); $this->packageVersion->setAttribute('dir', __DIR__); $this->em->persist($this->package); $this->otherPackage = new Package('bar'); $this->otherPackageVersion = $this->otherPackage->createVersion('0.1'); $this->otherPackageVersion->setAttribute('dir', __DIR__); $this->em->persist($this->otherPackage); $this->em->flush(); }
public function testLoadConstant() { $this->versionA->addConstant($fooA = new GlobalConstant('FOO')); $fooA->setPhpType($this->typeRegistry->getNativeType('string')); $this->versionB->addConstant($fooB = new GlobalConstant('FOO')); $fooB->setPhpType($this->typeRegistry->getNativeType('string')); $this->em->persist($this->package); $this->em->flush(); $loadedConst = $this->provider->loadConstant('FOO'); $this->assertSame($fooA, $loadedConst, 'loadConstant() takes the first constant if no package versions are set.'); $loadedConst = $this->provider->loadConstant('foo'); $this->assertNull($loadedConst, 'loadConstant() treats the name **not** as case-insensitive.'); $this->provider->setPackageVersions(array($this->versionB)); $loadedConst = $this->provider->loadConstant('FOO'); $this->assertSame($fooB, $loadedConst, 'loadConstant() takes the constant from one of the set packages.'); $this->provider->setPackageVersions(array($this->versionC)); $this->assertNull($this->provider->loadConstant('FOO'), 'loadConstant() returns null if constant is not found in set packages.'); $this->assertNull($this->provider->loadConstant('BAR'), 'loadConstant() returns null if constant does not exist.'); }
public function dependsOn(PackageVersion $otherPackage) { foreach ($this->dependencies as $dep) { if ($dep->getVersion() === $otherPackage->getVersion() && $dep->getPackage()->getName() === $otherPackage->getPackage()->getName()) { return true; } } return false; }