Skip to content

Commit

Permalink
Merge pull request #5549 from cakephp/3.0-hhvm-fixes
Browse files Browse the repository at this point in the history
3.0 hhvm fixes
  • Loading branch information
markstory committed Jan 3, 2015
2 parents 4fe7818 + 7728e35 commit fb2ec09
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 45 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -14,6 +14,7 @@ env:

services:
- memcached
- redis-server

matrix:
allow_failures:
Expand Down
3 changes: 2 additions & 1 deletion src/Cache/Engine/MemcachedEngine.php
Expand Up @@ -159,7 +159,8 @@ public function init(array $config = [])
}

if ($this->_config['username'] !== null && $this->_config['password'] !== null) {
if (!method_exists($this->_Memcached, 'setSaslAuthData')) {
$sasl = method_exists($this->_Memcached, 'setSaslAuthData') && ini_get('memcached.use_sasl');
if (!$sasl) {
throw new InvalidArgumentException(
'Memcached extension is not build with SASL support'
);
Expand Down
3 changes: 0 additions & 3 deletions src/Network/Session.php
Expand Up @@ -136,7 +136,6 @@ protected static function _defaultConfig($name)
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'url_rewriter.tags' => '',
'session.serialize_handler' => 'php',
'session.use_cookies' => 1,
'session.save_path' => TMP . 'sessions',
Expand All @@ -147,7 +146,6 @@ protected static function _defaultConfig($name)
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'url_rewriter.tags' => '',
'session.use_cookies' => 1,
'session.save_handler' => 'user',
],
Expand All @@ -160,7 +158,6 @@ protected static function _defaultConfig($name)
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'url_rewriter.tags' => '',
'session.use_cookies' => 1,
'session.save_handler' => 'user',
'session.serialize_handler' => 'php',
Expand Down
33 changes: 12 additions & 21 deletions src/ORM/ResultSet.php
Expand Up @@ -217,21 +217,23 @@ public function rewind()
*/
public function valid()
{
if (isset($this->_results[$this->_index])) {
if ($this->_index >= $this->_count) {
if ($this->_statement !== null) {
$this->_statement->closeCursor();
}
return false;
}

if ($this->_useBuffering && $this->_results[$this->_index] !== null) {
$this->_current = $this->_results[$this->_index];
return true;
}

$this->_current = $this->_fetchResult();
$valid = $this->_current !== false;
$hasNext = $this->_index < $this->_count;

if ($this->_statement && !($valid && $hasNext)) {
$this->_statement->closeCursor();
}

if ($valid) {
$this->_bufferResult($this->_current);
if ($this->_useBuffering) {
$this->_results[$this->_index] = $this->_current;
}

return $valid;
Expand Down Expand Up @@ -263,6 +265,8 @@ public function serialize()
public function unserialize($serialized)
{
$this->_results = unserialize($serialized);
$this->_useBuffering = true;
$this->_count = count($this->_results);
}

/**
Expand Down Expand Up @@ -486,19 +490,6 @@ protected function _castValues($table, $values)
return $values;
}

/**
* Conditionally buffer the passed result
*
* @param array $result the result fetch from the database
* @return void
*/
protected function _bufferResult($result)
{
if ($this->_useBuffering) {
$this->_results[$this->_index] = $result;
}
}

/**
* Returns an array that can be used to describe the internal state of this
* object.
Expand Down
8 changes: 7 additions & 1 deletion src/View/ViewVarsTrait.php
Expand Up @@ -91,7 +91,13 @@ public function createView($viewClass = null)
if (!$className) {
throw new Exception\MissingViewException([$viewClass]);
}
$viewOptions = array_intersect_key(get_object_vars($this), array_flip($this->_validViewOptions));

$viewOptions = [];
foreach ($this->_validViewOptions as $option) {
if (property_exists($this, $option)) {
$viewOptions[$option] = $this->{$option};
}
}
return new $className($this->request, $this->response, $this->eventManager(), $viewOptions);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Cache/Engine/MemcachedEngineTest.php
Expand Up @@ -370,6 +370,8 @@ public function testIgbinarySerializerThrowException()
* test using authentication without memcached installed with SASL support
* throw an exception
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Memcached extension is not build with SASL support
* @return void
*/
public function testSaslAuthException()
Expand All @@ -383,7 +385,6 @@ public function testSaslAuthException()
'password' => 'password'
];

$this->setExpectedException('PHPUnit_Framework_Error_Warning');
$MemcachedEngine->init($config);
}

Expand Down Expand Up @@ -606,7 +607,7 @@ public function testDeleteCache()
*/
public function testDeleteMany()
{
$this->assertFalse(defined('HHVM_VERSION'), 'Crashes HHVM');
$this->skipIf(defined('HHVM_VERSION'), 'HHVM does not implement deleteMulti');
$this->_configCache();
$data = [
'App.falseTest' => false,
Expand Down Expand Up @@ -786,7 +787,6 @@ public function testConfigurationConflict()
*/
public function testClear()
{
$this->assertFalse(defined('HHVM_VERSION'), 'Crashes HHVM');
Cache::config('memcached2', [
'engine' => 'Memcached',
'prefix' => 'cake2_',
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/Core/ConfigureTest.php
Expand Up @@ -141,6 +141,10 @@ public function testWrite()
*/
public function testDebugSettingDisplayErrors()
{
$this->skipIf(
defined('HHVM_VERSION'),
'Cannot change display_errors at runtime in HHVM'
);
Configure::write('debug', false);
$result = ini_get('display_errors');
$this->assertEquals(0, $result);
Expand Down
5 changes: 5 additions & 0 deletions tests/TestCase/Error/DebuggerTest.php
Expand Up @@ -83,6 +83,10 @@ public function tearDown()
*/
public function testDocRef()
{
$this->skipIf(
defined('HHVM_VERSION'),
'HHVM does not output doc references'
);
ini_set('docref_root', '');
$this->assertEquals(ini_get('docref_root'), '');
new Debugger();
Expand All @@ -105,6 +109,7 @@ public function testExcerpt()
$this->assertTrue(is_array($result));
$this->assertCount(4, $result);

$this->skipIf(defined('HHVM_VERSION'), 'HHVM does not highlight php code');
$pattern = '/<code>.*?<span style\="color\: \#\d+">.*?&lt;\?php/';
$this->assertRegExp($pattern, $result[0]);

Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Error/ErrorHandlerTest.php
Expand Up @@ -121,7 +121,7 @@ public function testHandleErrorDebugOn()
$this->_restoreError = true;

ob_start();
$wrong .= '';
$wrong = $wrong + 1;
$result = ob_get_clean();

$this->assertRegExp('/<pre class="cake-error">/', $result);
Expand Down Expand Up @@ -199,7 +199,7 @@ public function testHandleErrorDebugOff()
'Notice (8): Undefined variable: out in [' . __FILE__ . ', line ' . (__LINE__ + 3) . ']' . "\n\n"
);

$out .= '';
$out = $out + 1;
}

/**
Expand All @@ -225,7 +225,7 @@ public function testHandleErrorLoggingTrace()
)
);

$out .= '';
$out = $out + 1;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions tests/TestCase/Network/ResponseTest.php
Expand Up @@ -383,9 +383,7 @@ public function testCache()
*/
public function testCompress()
{
if (php_sapi_name() !== 'cli') {
$this->markTestSkipped('The response compression can only be tested in cli.');
}
$this->skipIf(defined('HHVM_VERSION'), 'HHVM does not implement ob_gzhandler');

$response = new Response();
if (ini_get("zlib.output_compression") === '1' || !extension_loaded("zlib")) {
Expand Down Expand Up @@ -505,9 +503,8 @@ public function testOutputCompressed()
if (!extension_loaded("zlib")) {
$this->markTestSkipped('Skipping further tests for outputCompressed as zlib extension is not loaded');
}
if (php_sapi_name() !== 'cli') {
$this->markTestSkipped('Testing outputCompressed method with compression enabled done only in cli');
}

$this->skipIf(defined('HHVM_VERSION'), 'HHVM does not implement ob_gzhandler');

if (ini_get("zlib.output_compression") !== '1') {
ob_start('ob_gzhandler');
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/ORM/Behavior/CounterCacheBehaviorTest.php
Expand Up @@ -385,7 +385,7 @@ protected function _getEntity()
*/
protected function _getUser($id = 1)
{
return $this->user->find('all')->where(['id' => $id])->first();
return $this->user->get($id);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/ORM/QueryTest.php
Expand Up @@ -997,9 +997,9 @@ public function testResultsAreWrappedInMapReduce()
'\Database\StatementInterface',
['fetch', 'closeCursor', 'rowCount']
);
$statement->expects($this->exactly(3))
$statement->expects($this->exactly(2))
->method('fetch')
->will($this->onConsecutiveCalls(['a' => 1], ['a' => 2], false));
->will($this->onConsecutiveCalls(['a' => 1], ['a' => 2]));

$statement->expects($this->once())
->method('rowCount')
Expand Down
7 changes: 3 additions & 4 deletions tests/TestCase/Shell/CommandListShellTest.php
Expand Up @@ -113,19 +113,18 @@ public function testMain()
*/
public function testMainXml()
{
$this->assertFalse(defined('HHVM_VERSION'), 'Remove when travis updates to hhvm 2.5');
$this->Shell->params['xml'] = true;
$this->Shell->main();

$output = $this->out->output;

$find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"/>';
$find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"';
$this->assertContains($find, $output);

$find = '<shell name="orm_cache" call_as="orm_cache" provider="CORE" help="orm_cache -h"/>';
$find = '<shell name="orm_cache" call_as="orm_cache" provider="CORE" help="orm_cache -h"';
$this->assertContains($find, $output);

$find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"/>';
$find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"';
$this->assertContains($find, $output);
}
}
5 changes: 5 additions & 0 deletions tests/TestCase/Shell/PluginAssetsShellTest.php
Expand Up @@ -42,6 +42,11 @@ public function setUp()
'Skip PluginAssetsShell tests on windows to prevent side effects for UrlHelper tests on AppVeyor.'
);

$this->skipIf(
defined('HHVM_VERSION'),
'Also broken in HHVM, maybe the tests are wrong?'
);

$this->io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);

$this->shell = $this->getMock(
Expand Down

0 comments on commit fb2ec09

Please sign in to comment.