public function setUp() { parent::setUp(); if (null !== self::$DI) { unset(self::$DI['app']['dbal.provider']); } self::$DI = new \Pimple(); ini_set('memory_limit', '4096M'); \PHPUnit_Framework_Error_Warning::$enabled = true; \PHPUnit_Framework_Error_Notice::$enabled = true; self::$DI['app'] = self::$DI->share(function ($DI) { return $this->loadApp('/lib/Alchemy/Phrasea/Application/Root.php'); }); self::$DI['cli'] = self::$DI->share(function ($DI) { return $this->loadCLI(); }); self::$DI['local-guzzle'] = self::$DI->share(function ($DI) { return new Guzzle(self::$DI['app']['conf']->get('servername')); }); self::$DI['client'] = self::$DI->share(function ($DI) { return new Client($DI['app'], []); }); self::$DI['user'] = self::$DI->share(function ($DI) { return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit']); }); self::$DI['user_1'] = self::$DI->share(function ($DI) { return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_1']); }); self::$DI['user_2'] = self::$DI->share(function ($DI) { return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_2']); }); self::$DI['user_3'] = self::$DI->share(function ($DI) { return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_3']); }); self::$DI['user_guest'] = self::$DI->share(function ($DI) { return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_guest']); }); self::$DI['user_notAdmin'] = self::$DI->share(function ($DI) { return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit_not_admin']); }); self::$DI['user_alt1'] = self::$DI->share(function ($DI) { return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit_alt1']); }); self::$DI['user_alt2'] = self::$DI->share(function ($DI) { return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit_alt2']); }); self::$DI['user_template'] = self::$DI->share(function ($DI) { return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_template']); }); self::$DI['registration_1'] = self::$DI->share(function ($DI) { return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_1']); }); self::$DI['registration_2'] = self::$DI->share(function ($DI) { return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_2']); }); self::$DI['registration_3'] = self::$DI->share(function ($DI) { return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_3']); }); self::$DI['oauth2-app-user'] = self::$DI->share(function ($DI) { return new \API_OAuth2_Application($DI['app'], self::$fixtureIds['oauth']['user']); }); self::$DI['oauth2-app-user_notAdmin'] = self::$DI->share(function ($DI) { return new \API_OAuth2_Application($DI['app'], self::$fixtureIds['oauth']['user_notAdmin']); }); self::$DI['logger'] = self::$DI->share(function () { $logger = new Logger('tests'); $logger->pushHandler(new NullHandler()); return $logger; }); self::$DI['collection'] = self::$DI->share(function ($DI) { return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll']); }); self::$DI['collection_no_access'] = self::$DI->share(function ($DI) { return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll_no_access']); }); self::$DI['collection_no_access_by_status'] = self::$DI->share(function ($DI) { return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll_no_status']); }); if (!self::$booted) { if (!self::$DI['app']['phraseanet.configuration-tester']->isInstalled()) { echo "[0;31mPhraseanet is not set up[0;37m\n"; exit(1); } self::$fixtureIds = array_merge(self::$fixtureIds, json_decode(file_get_contents(__DIR__ . '/../fixtures.json'), true)); self::resetUsersRights(self::$DI['app'], self::$DI['user']); self::resetUsersRights(self::$DI['app'], self::$DI['user_notAdmin']); self::$booted = true; } self::$DI['lazaret_1'] = self::$DI->share(function ($DI) { return $DI['app']['EM']->find('Phraseanet:LazaretFile', self::$fixtureIds['lazaret']['lazaret_1']); }); foreach (range(1, 7) as $i) { self::$DI['record_' . $i] = self::$DI->share(function ($DI) use($i) { return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], self::$fixtureIds['record']['record_' . $i]); }); } foreach (range(1, 3) as $i) { self::$DI['record_story_' . $i] = self::$DI->share(function ($DI) use($i) { return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], self::$fixtureIds['record']['record_story_' . $i]); }); } self::$DI['record_no_access_resolver'] = self::$DI->protect(function () { $id = 'no_access'; if (isset(self::$fixtureIds['records'][$id])) { return self::$fixtureIds['records'][$id]; } self::$recordsInitialized[] = $id; $file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), self::$DI['collection_no_access']); $record = record_adapter::createFromFile($file, self::$DI['app']); self::$DI['app']['subdef.generator']->generateSubdefs($record); self::$fixtureIds['records'][$id] = $record->get_record_id(); return self::$fixtureIds['records'][$id]; }); self::$DI['record_no_access_by_status_resolver'] = self::$DI->protect(function () { $id = 'no_access_by_status'; if (isset(self::$fixtureIds['records'][$id])) { return self::$fixtureIds['records'][$id]; } self::$recordsInitialized[] = $id; $file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), self::$DI['collection_no_access_by_status']); $record = record_adapter::createFromFile($file, self::$DI['app']); self::$DI['app']['subdef.generator']->generateSubdefs($record); self::$fixtureIds['records'][$id] = $record->get_record_id(); return self::$fixtureIds['records'][$id]; }); self::$DI['record_no_access'] = self::$DI->share(function ($DI) { return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], $DI['record_no_access_resolver']()); }); self::$DI['record_no_access_by_status'] = self::$DI->share(function ($DI) { return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], $DI['record_no_access_by_status_resolver']()); }); if (!self::$testCaseBooted) { $this->bootTestCase(); } self::$testCaseBooted = true; }
public function setUp() { parent::setUp(); self::$DI = new \Pimple(); ini_set('memory_limit', '4096M'); error_reporting(-1); \PHPUnit_Framework_Error_Warning::$enabled = true; \PHPUnit_Framework_Error_Notice::$enabled = true; self::$DI['app'] = self::$DI->share(function ($DI) { return $this->loadApp($this->getApplicationPath()); }); self::$DI['cli'] = self::$DI->share(function ($DI) { return $this->loadCLI(); }); self::$DI['local-guzzle'] = self::$DI->share(function ($DI) { return new Guzzle(self::$DI['app']['conf']->get('servername')); }); self::$DI['client'] = self::$DI->share(function ($DI) { return new Client($DI['app'], []); }); self::$DI['feed_public'] = self::$DI->share(function ($DI) { return $DI['app']['repo.feeds']->find(self::$fixtureIds['feed']['public']['feed']); }); self::$DI['feed_public_entry'] = self::$DI->share(function ($DI) { return $DI['app']['repo.feed-entries']->find(self::$fixtureIds['feed']['public']['entry']); }); self::$DI['feed_public_token'] = self::$DI->share(function ($DI) { return $DI['app']['repo.feed-tokens']->find(self::$fixtureIds['feed']['public']['token']); }); self::$DI['feed_private'] = self::$DI->share(function ($DI) { return $DI['app']['repo.feeds']->find(self::$fixtureIds['feed']['private']['feed']); }); self::$DI['feed_private_entry'] = self::$DI->share(function ($DI) { return $DI['app']['repo.feed-entries']->find(self::$fixtureIds['feed']['private']['entry']); }); self::$DI['feed_private_token'] = self::$DI->share(function ($DI) { return $DI['app']['repo.feed-tokens']->find(self::$fixtureIds['feed']['private']['token']); }); self::$DI['basket_1'] = self::$DI->share(function ($DI) { return $DI['app']['repo.baskets']->find(self::$fixtureIds['basket']['basket_1']); }); self::$DI['basket_2'] = self::$DI->share(function ($DI) { return $DI['app']['repo.baskets']->find(self::$fixtureIds['basket']['basket_2']); }); self::$DI['basket_3'] = self::$DI->share(function ($DI) { return $DI['app']['repo.baskets']->find(self::$fixtureIds['basket']['basket_3']); }); self::$DI['basket_4'] = self::$DI->share(function ($DI) { return $DI['app']['repo.baskets']->find(self::$fixtureIds['basket']['basket_4']); }); self::$DI['token_1'] = self::$DI->share(function ($DI) { return $DI['app']['repo.tokens']->find(self::$fixtureIds['token']['token_1']); }); self::$DI['token_2'] = self::$DI->share(function ($DI) { return $DI['app']['repo.tokens']->find(self::$fixtureIds['token']['token_2']); }); self::$DI['token_invalid'] = self::$DI->share(function ($DI) { return $DI['app']['repo.tokens']->find(self::$fixtureIds['token']['token_invalid']); }); self::$DI['token_validation'] = self::$DI->share(function ($DI) { return $DI['app']['repo.tokens']->find(self::$fixtureIds['token']['token_validation']); }); $users = ['user' => 'test_phpunit', 'user_1' => 'user_1', 'user_2' => 'user_2', 'user_3' => 'user_3', 'user_guest' => 'user_guest', 'user_notAdmin' => 'test_phpunit_not_admin', 'user_alt1' => 'test_phpunit_alt1', 'user_alt2' => 'test_phpunit_alt2', 'user_template' => 'user_template']; $userFactory = function ($fixtureName) { if ('user_guest' === $fixtureName) { return function ($DI) use($fixtureName) { return $DI['app']['repo.users']->find(self::$fixtureIds['user'][$fixtureName]); }; } return function ($DI) use($fixtureName) { $user = $DI['app']['repo.users']->find(self::$fixtureIds['user'][$fixtureName]); self::resetUsersRights($DI['app'], $user); return $user; }; }; foreach ($users as $name => $fixtureName) { self::$DI[$name] = self::$DI->share($userFactory($fixtureName)); } self::$DI['registration_1'] = self::$DI->share(function ($DI) { return $DI['app']['repo.registrations']->find(self::$fixtureIds['registrations']['registration_1']); }); self::$DI['registration_2'] = self::$DI->share(function ($DI) { return $DI['app']['repo.registrations']->find(self::$fixtureIds['registrations']['registration_2']); }); self::$DI['registration_3'] = self::$DI->share(function ($DI) { return $DI['app']['repo.registrations']->find(self::$fixtureIds['registrations']['registration_3']); }); self::$DI['oauth2-app-user'] = self::$DI->share(function ($DI) { return $DI['app']['repo.api-applications']->find(self::$fixtureIds['oauth']['user']); }); self::$DI['webhook-event'] = self::$DI->share(function ($DI) { return $DI['app']['repo.webhook-event']->find(self::$fixtureIds['webhook']['event']); }); self::$DI['oauth2-app-user-not-admin'] = self::$DI->share(function ($DI) { return $DI['app']['repo.api-applications']->find(self::$fixtureIds['oauth']['user-not-admin']); }); self::$DI['oauth2-app-acc-user'] = self::$DI->share(function ($DI) { return $DI['app']['repo.api-accounts']->find(self::$fixtureIds['oauth']['acc-user']); }); self::$DI['oauth2-app-acc-user-not-admin'] = self::$DI->share(function ($DI) { return $DI['app']['repo.api-accounts']->find(self::$fixtureIds['oauth']['acc-user-not-admin']); }); self::$DI['logger'] = self::$DI->share(function () { $logger = new Logger('tests'); $logger->pushHandler(new NullHandler()); return $logger; }); self::$DI['collection'] = self::$DI->share(function ($DI) { return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll']); }); self::$DI['collection_no_access'] = self::$DI->share(function ($DI) { return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll_no_access']); }); self::$DI['collection_no_access_by_status'] = self::$DI->share(function ($DI) { return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll_no_status']); }); self::$DI['lazaret_1'] = self::$DI->share(function ($DI) { return $DI['app']['orm.em']->find('Phraseanet:LazaretFile', self::$fixtureIds['lazaret']['lazaret_1']); }); foreach (range(1, 7) as $i) { self::$DI['record_' . $i] = self::$DI->share(function ($DI) use($i) { return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], self::$fixtureIds['record']['record_' . $i]); }); } foreach (range(1, 3) as $i) { self::$DI['record_story_' . $i] = self::$DI->share(function ($DI) use($i) { return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], self::$fixtureIds['record']['record_story_' . $i]); }); } self::$DI['record_no_access_resolver'] = self::$DI->protect(function () { $id = 'no_access'; if (isset(self::$fixtureIds['records'][$id])) { return self::$fixtureIds['records'][$id]; } self::$recordsInitialized[] = $id; $file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), self::$DI['collection_no_access']); $record = record_adapter::createFromFile($file, self::$DI['app']); self::$DI['app']['subdef.generator']->generateSubdefs($record); self::$fixtureIds['records'][$id] = $record->get_record_id(); return self::$fixtureIds['records'][$id]; }); self::$DI['record_no_access_by_status_resolver'] = self::$DI->protect(function () { $id = 'no_access_by_status'; if (isset(self::$fixtureIds['records'][$id])) { return self::$fixtureIds['records'][$id]; } self::$recordsInitialized[] = $id; $file = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess(__DIR__ . '/../files/cestlafete.jpg'), self::$DI['collection_no_access_by_status']); $record = record_adapter::createFromFile($file, self::$DI['app']); self::$DI['app']['subdef.generator']->generateSubdefs($record); self::$fixtureIds['records'][$id] = $record->get_record_id(); return self::$fixtureIds['records'][$id]; }); self::$DI['record_no_access'] = self::$DI->share(function ($DI) { return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], $DI['record_no_access_resolver']()); }); self::$DI['record_no_access_by_status'] = self::$DI->share(function ($DI) { return new \record_adapter($DI['app'], self::$fixtureIds['databox']['records'], $DI['record_no_access_by_status_resolver']()); }); static $decodedFixtureIds; if (is_null($decodedFixtureIds)) { $decodedFixtureIds = json_decode(file_get_contents(sys_get_temp_dir() . '/fixtures.json'), true); } self::$fixtureIds = $decodedFixtureIds; }