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 18, 2023
1 parent 2a68033 commit 603deb1
Show file tree
Hide file tree
Showing 646 changed files with 31,511 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ jobs:
run: php data/bin/check_configuration.php

- name: Run Tests
run: php data/bin/symfony symfony:test --trace
run: php vendor/bin/phpunit
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
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 = null;

/**
* Class constructor.
Expand Down
1 change: 1 addition & 0 deletions lib/service/sfServiceContainerDumperGraphviz.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class sfServiceContainerDumperGraphviz extends sfServiceContainerDumper
{
protected $nodes;
protected $edges;
protected /*array*/ $options;

/**
* Dumps the service container as a graphviz graph.
Expand Down
55 changes: 55 additions & 0 deletions lib/test/Symfony1ApplicationTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

Check warning on line 1 in lib/test/Symfony1ApplicationTestCase.php

View workflow job for this annotation

GitHub Actions / PHP-CS-Fixer

Found violation(s) of type: php_unit_internal_class

Check warning on line 1 in lib/test/Symfony1ApplicationTestCase.php

View workflow job for this annotation

GitHub Actions / PHP-CS-Fixer

Found violation(s) of type: php_unit_test_class_requires_covers

Check warning on line 1 in lib/test/Symfony1ApplicationTestCase.php

View workflow job for this annotation

GitHub Actions / PHP-CS-Fixer

Found violation(s) of type: phpdoc_separation

Check warning on line 1 in lib/test/Symfony1ApplicationTestCase.php

View workflow job for this annotation

GitHub Actions / PHP-CS-Fixer

Found violation(s) of type: single_line_empty_body

Check warning on line 1 in lib/test/Symfony1ApplicationTestCase.php

View workflow job for this annotation

GitHub Actions / PHP-CS-Fixer

Found violation(s) of type: single_blank_line_at_eof

/*
* This file is part of the symfony package.
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use PHPUnit\Framework\TestCase;

class Symfony1ApplicationTestCase extends TestCase
{
public function resetSfConfig()
{
sfConfig::set('sf_symfony_lib_dir', realpath(__DIR__.'/../lib'));
sfConfig::set('sf_test_cache_dir', sys_get_temp_dir().'/sf_test_project');
}

public function getEnvironment()
{
return 'test';
}

public function getDebug()
{
return true;
}

public function getEventDispatcher()
{
return null;
}

public function getRootDir()
{
return null;
}

public function projectSetup(sfApplicationConfiguration $applicationConfiguration)
{
}

public function getApplicationConfiguration()
{
return new TestCaseDrivenApplicationConfiguration(
$this,
$this->getEnvironment(),
$this->getDebug(),
$this->getRootDir(),
$this->getEventDispatcher()
);
}
}
Loading

0 comments on commit 603deb1

Please sign in to comment.