Skip to content

Commit

Permalink
[test] add phpunit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
connorhu committed Dec 19, 2023
1 parent 2a68033 commit af3db2c
Show file tree
Hide file tree
Showing 669 changed files with 31,997 additions and 40 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php-version }}"
extensions: "json,memcached,apcu"
ini-values: date.timezone=UTC,memory_limit=-1,apc.enable_cli=1
tools: pecl

- name: Get composer cache directory
id: composer-cache
Expand All @@ -58,4 +61,6 @@ jobs:
run: php data/bin/check_configuration.php

- name: Run Tests
run: php data/bin/symfony symfony:test --trace
run: php vendor/bin/phpunit
env:
MEMCACHED_HOST: 'localhost:11211'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ lib/plugins/sfDoctrinePlugin/test/functional/fixtures/log/
/vendor
/composer.lock
.php-cs-fixer.cache
.phpunit.result.cache
phpunit.xml
4 changes: 2 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
->exclude('task/generator/skeleton/')
->exclude('plugins/sfDoctrinePlugin/data/generator/')
// Exclude generated files (single files)
->notPath('unit/config/fixtures/sfDefineEnvironmentConfigHandler/prefix_result.php')
->notPath('unit/config/fixtures/sfFilterConfigHandler/result.php')
->notPath('fixtures/sfDefineEnvironmentConfigHandler/prefix_result.php')
->notPath('fixtures/sfFilterConfigHandler/result.php')
;

$config = new PhpCsFixer\Config();
Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"swiftmailer/swiftmailer": "~5.2 || ^6.0"
},
"require-dev": {
"psr/log": "*"
"ext-zlib": "*",
"ext-apcu": "*",
"psr/log": "*",
"phpunit/phpunit": "^9.6"
},
"autoload": {
"files": ["autoload.php"]
Expand All @@ -26,5 +29,9 @@
"replace": {
"lexpress/symfony1": "^1.5"
},
"scripts": {
"test": "phpunit",
"php-cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix"
},
"bin": ["data/bin/symfony"]
}
5 changes: 5 additions & 0 deletions lib/autoload/sfCoreAutoload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ class sfCoreAutoload
'sftesterresponse' => 'test/sfTesterResponse.class.php',
'sftesteruser' => 'test/sfTesterUser.class.php',
'sftesterviewcache' => 'test/sfTesterViewCache.class.php',
'symfony1applicationtestcase' => 'test/Symfony1ApplicationTestCase.php',
'symfony1projecttestcase' => 'test/Symfony1ProjectTestCase.php',
'testcasedrivenapplicationconfiguration' => 'test/TestCaseDrivenApplicationConfiguration.php',
'testcasedrivenconfigurationinterface' => 'test/TestCaseDrivenConfigurationInterface.php',
'testcasedrivenprojectconfiguration' => 'test/TestCaseDrivenProjectConfiguration.php',
'sfbasicsecurityuser' => 'user/sfBasicSecurityUser.class.php',
'sfsecurityuser' => 'user/sfSecurityUser.class.php',
'sfuser' => 'user/sfUser.class.php',
Expand Down
18 changes: 10 additions & 8 deletions lib/cache/sfAPCCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function initialize($options = array())
{
parent::initialize($options);

$this->enabled = function_exists('apc_store') && ini_get('apc.enabled');
$this->enabled = function_exists('apcu_store') && apcu_enabled();
}

/**
Expand Down Expand Up @@ -69,14 +69,16 @@ public function has($key)
* @see sfCache
*
* @param mixed|null $lifetime
*
* @return bool|array
*/
public function set($key, $data, $lifetime = null)
{
if (!$this->enabled) {
return true;
}

return apc_store($this->getOption('prefix').$key, $data, $this->getLifetime($lifetime));
return apcu_store($this->getOption('prefix').$key, $data, $this->getLifetime($lifetime));
}

/**
Expand All @@ -88,7 +90,7 @@ public function remove($key)
return true;
}

return apc_delete($this->getOption('prefix').$key);
return apcu_delete($this->getOption('prefix').$key);
}

/**
Expand All @@ -101,7 +103,7 @@ public function clean($mode = sfCache::ALL)
}

if (sfCache::ALL === $mode) {
return apc_clear_cache('user');
return apcu_clear_cache();
}
}

Expand Down Expand Up @@ -138,7 +140,7 @@ public function removePattern($pattern)
return true;
}

$infos = apc_cache_info('user');
$infos = apcu_cache_info();
if (!is_array($infos['cache_list'])) {
return;
}
Expand All @@ -147,7 +149,7 @@ public function removePattern($pattern)

foreach ($infos['cache_list'] as $info) {
if (preg_match($regexp, $info['info'])) {
apc_delete($info['info']);
apcu_delete($info['info']);
}
}
}
Expand All @@ -165,7 +167,7 @@ protected function getCacheInfo($key)
return false;
}

$infos = apc_cache_info('user');
$infos = apcu_cache_info();

if (is_array($infos['cache_list'])) {
foreach ($infos['cache_list'] as $info) {
Expand All @@ -181,7 +183,7 @@ protected function getCacheInfo($key)
private function fetch($key, &$success)
{
$has = null;
$value = apc_fetch($key, $has);
$value = apcu_fetch($key, $has);
// the second argument was added in APC 3.0.17. If it is still null we fall back to the value returned
if (null !== $has) {
$success = $has;
Expand Down
2 changes: 2 additions & 0 deletions lib/cache/sfEAcceleratorCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @author Fabien Potencier <[email protected]>
*
* @version SVN: $Id$
*
* @deprecated
*/
class sfEAcceleratorCache extends sfCache
{
Expand Down
12 changes: 11 additions & 1 deletion lib/cache/sfFileCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ public function get($key, $default = null)
return $default;
}

return $data[self::READ_DATA];
$rawData = $data[self::READ_DATA];

if ('FaLSe' === $rawData) {
$rawData = false;
}

return $rawData;
}

/**
Expand All @@ -87,6 +93,10 @@ public function set($key, $data, $lifetime = null)
$this->clean(sfCache::OLD);
}

if (false === $data) {
$data = 'FaLSe';
}

return $this->write($this->getFilePath($key), $data, time() + $this->getLifetime($lifetime));
}

Expand Down
10 changes: 9 additions & 1 deletion lib/cache/sfSQLiteCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public function get($key, $default = null)
$data = $this->dbh->singleQuery(sprintf("SELECT data FROM cache WHERE key = '%s' AND timeout > %d", sqlite_escape_string($key), time()));
}

if ('FaLSe' === $data) {
$data = false;
}

return null === $data ? $default : $data;
}

Expand All @@ -81,7 +85,7 @@ public function get($key, $default = null)
public function has($key)
{
if ($this->isSqLite3()) {
return (int) $this->dbh->querySingle(sprintf("SELECT count(*) FROM cache WHERE key = '%s' AND timeout > %d", $this->dbh->escapeString($key), time()));
return $this->dbh->querySingle(sprintf("SELECT count(*) FROM cache WHERE key = '%s' AND timeout > %d", $this->dbh->escapeString($key), time())) > 0;
}

return (bool) $this->dbh->query(sprintf("SELECT key FROM cache WHERE key = '%s' AND timeout > %d", sqlite_escape_string($key), time()))->numRows();
Expand All @@ -98,6 +102,10 @@ public function set($key, $data, $lifetime = null)
$this->clean(sfCache::OLD);
}

if (false === $data) {
$data = 'FaLSe';
}

if ($this->isSqLite3()) {
return $this->dbh->exec(sprintf("INSERT OR REPLACE INTO cache (key, data, timeout, last_modified) VALUES ('%s', '%s', %d, %d)", $this->dbh->escapeString($key), $this->dbh->escapeString($data), time() + $this->getLifetime($lifetime), time()));
}
Expand Down
2 changes: 2 additions & 0 deletions lib/cache/sfXCacheCache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @author Fabien Potencier <[email protected]>
*
* @version SVN: $Id$
*
* @deprecated
*/
class sfXCacheCache extends sfCache
{
Expand Down
2 changes: 1 addition & 1 deletion lib/command/sfCommandOption.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getName()
*/
public function acceptParameter()
{
return $this->isParameterRequired() || $this->isParameterOptional();
return self::PARAMETER_NONE !== (self::PARAMETER_NONE & $this->mode);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions lib/database/sfMySQLDatabase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@
* @author Sean Kerr <[email protected]>
*
* @version SVN: $Id$
*
* @deprecated
*/
class sfMySQLDatabase extends sfDatabase
{
/**
* Connects to the database.
*
* @throws <b>sfDatabaseException</b> If a connection could not be created
*
* @deprecated
*/
public function connect()
{
@trigger_error('sfMySQLDatabase storage is deprecated. use sfMySQLiDatabase instead.', \E_USER_DEPRECATED);

$database = $this->getParameter('database');
$host = $this->getParameter('host', 'localhost');
$password = $this->getParameter('password');
Expand Down Expand Up @@ -78,9 +84,13 @@ public function connect()
* Execute the shutdown procedure.
*
* @throws <b>sfDatabaseException</b> If an error occurs while shutting down this database
*
* @deprecated
*/
public function shutdown()
{
@trigger_error('sfMySQLDatabase storage is deprecated. use sfMySQLiDatabase instead.', \E_USER_DEPRECATED);

if (null != $this->connection) {
@mysql_close($this->connection);
}
Expand All @@ -92,9 +102,13 @@ public function shutdown()
* @param bool $persistent wether persistent connections are use or not
*
* @return string name of connect method
*
* @deprecated
*/
protected function getConnectMethod($persistent)
{
@trigger_error('sfMySQLDatabase storage is deprecated. use sfMySQLiDatabase instead.', \E_USER_DEPRECATED);

return $persistent ? 'mysql_pconnect' : 'mysql_connect';
}

Expand All @@ -104,9 +118,13 @@ protected function getConnectMethod($persistent)
* @param string $database Name of database to be connected
*
* @return bool true if this was successful
*
* @deprecated
*/
protected function selectDatabase($database)
{
@trigger_error('sfMySQLDatabase storage is deprecated. use sfMySQLiDatabase instead.', \E_USER_DEPRECATED);

return null != $database && !@mysql_select_db($database, $this->connection);
}
}
13 changes: 11 additions & 2 deletions lib/form/sfForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,17 @@ public function mergeForm(sfForm $form)
$this->validatorSchema[$field] = $validator;
}

$this->getWidgetSchema()->setLabels($form->getWidgetSchema()->getLabels() + $this->getWidgetSchema()->getLabels());
$this->getWidgetSchema()->setHelps($form->getWidgetSchema()->getHelps() + $this->getWidgetSchema()->getHelps());
$labels = $this->getWidgetSchema()->getLabels();
foreach ($form->getWidgetSchema()->getLabels() as $name => $label) {
$labels[$name] = $label;
}
$this->getWidgetSchema()->setLabels($labels);

$helps = $this->getWidgetSchema()->getHelps();
foreach ($form->getWidgetSchema()->getHelps() as $name => $help) {
$helps[$name] = $help;
}
$this->getWidgetSchema()->setHelps($helps);

$this->mergePreValidator($form->getValidatorSchema()->getPreValidator());
$this->mergePostValidator($form->getValidatorSchema()->getPostValidator());
Expand Down
4 changes: 2 additions & 2 deletions lib/i18n/sfI18N.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,12 @@ public function getDateForCulture($date, $culture = null)
* @param string $time The formatted date as string
* @param string $culture The culture
*
* @return array An array with the hour and minute
* @return array|null An array with the hour and minute
*/
public function getTimeForCulture($time, $culture = null)
{
if (!$time) {
return 0;
return null;
}

$culture = null === $culture ? $this->culture : $culture;
Expand Down
4 changes: 3 additions & 1 deletion lib/i18n/sfMessageSource_XLIFF.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ class sfMessageSource_XLIFF extends sfMessageSource_File
*/
public function &loadData($filename)
{
$translations = false;

libxml_use_internal_errors(true);
if (!$xml = simplexml_load_file($filename)) {
return false;
return $translations;
}
libxml_use_internal_errors(false);

Expand Down
2 changes: 1 addition & 1 deletion lib/mailer/sfMailer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(sfEventDispatcher $dispatcher, $options)
'logging' => false,
'delivery_strategy' => self::REALTIME,
'transport' => array(
'class' => 'Swift_MailTransport',
'class' => 'Swift_SendmailTransport',
'param' => array(),
),
), $options);
Expand Down
4 changes: 3 additions & 1 deletion lib/plugin/sfPearConfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function &getREST($version, $options = array())
{
$class = 'sfPearRest'.str_replace('.', '', $version);

return new $class($this, $options);
$instance = new $class($this, $options);

return $instance;
}
}
3 changes: 2 additions & 1 deletion lib/plugin/sfPluginManager.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ protected function isPluginCompatibleWithDependency($dependency)
*/
protected function checkDependency($dependency)
{
$dependencyChecker = new PEAR_Dependency2($this->environment->getConfig(), array(), array('package' => '', 'channel' => ''));
$config = $this->environment->getConfig();
$dependencyChecker = new PEAR_Dependency2($config, array(), array('package' => '', 'channel' => ''));

PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$e = $dependencyChecker->validatePackageDependency($dependency, true, array());
Expand Down
2 changes: 1 addition & 1 deletion lib/request/sfWebRequest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public function getLanguages()
return $this->languages;
}

if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) || empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
return array();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/response/sfResponse.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class sfResponse implements Serializable
protected $dispatcher;

/** @var string */
protected $content = '';
protected $content;

/**
* Class constructor.
Expand Down
Loading

0 comments on commit af3db2c

Please sign in to comment.