Skip to content

Instantly share code, notes, and snippets.

@tobiasgies
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobiasgies/9723617 to your computer and use it in GitHub Desktop.
Save tobiasgies/9723617 to your computer and use it in GitHub Desktop.
HHVM: Issue with disabling original constructor of builtin classes

Test Code:

<?php

namespace TobiasGies;

class HHVMCompatibilityTest extends \PHPUnit_Framework_TestCase {
  public function testCreateDummyWithDisabledConstructor() {
    $mock = $this
      ->getMockBuilder('TobiasGies\HHVMCompatibilityTest_Dummy')
      ->disableOriginalConstructor()
      ->getMock();
    $this->assertNotEquals('__PHP_Unserializable_Class', get_class($mock));
    $this->assertInstanceOf('TobiasGies\HHVMCompatibilityTest_Dummy', $mock);
  }

  public function testCreateDOMDocumentWithDisabledConstructor() {
    $mock = $this
      ->getMockBuilder('DOMDocument')
      ->disableOriginalConstructor()
      ->getMock();
    $this->assertNotEquals('__PHP_Unserializable_Class', get_class($mock));
    $this->assertInstanceOf('DOMDocument', $mock);
  }
}

class HHVMCompatibilityTest_Dummy {
  private $foo;

  public function __construct($foo) {
    $this->foo = $foo;
  }
}

Output with PHP:

$ /usr/bin/php --version
PHP 5.5.9-1+sury.org~saucy+1 (cli) (built: Feb 13 2014 15:58:58) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
$ /usr/bin/php ~/phar/phpunit.phar HHVMCompatibilityTest.php
PHPUnit 4.0.12 by Sebastian Bergmann.

..

Time: 40 ms, Memory: 3.75Mb

OK (2 tests, 4 assertions)

Output with HHVM 2.4.2:

$ /usr/bin/hhvm --version        
HipHop VM 2.4.2 (rel)
Compiler: tags/HHVM-2.4.2-0-g432ecffa04b21c60953bb236a9db8278f4650537
Repo schema: 1be260b29a71097b5d1f78c6e4dcbb981ba03bde
$ /usr/bin/hhvm ~/phar/phpunit.phar HHVMCompatibilityTest.php
PHPUnit 4.0.12 by Sebastian Bergmann.

.F

Time: 84 ms, Memory: 10.89Mb

There was 1 failure:

1) TobiasGies\HHVMCompatibilityTest::testCreateDOMDocumentWithDisabledConstructor
Failed asserting that '__PHP_Unserializable_Class' is not equal to <string:__PHP_Unserializable_Class>.

/home/tobias/sources/playground/HHVMCompatibilityTest.php:20

FAILURES!
Tests: 2, Assertions: 3, Failures: 1.

Output with HHVM master:

$ ~/sources/hhvm/hphp/hhvm/hhvm --version                                                          
HipHop VM 3.0.0-dev (rel)
Compiler: heads/master-0-g5b00837d9b2ecc28e6225336296be88449637b2e
Repo schema: b602fe3a78ec9eec7b65ec874110b9323ceabf88
$ ~/sources/hhvm/hphp/hhvm/hhvm ~/phar/phpunit.phar HHVMCompatibilityTest.php
PHPUnit 4.0.12 by Sebastian Bergmann.

.F

Time: 418 ms, Memory: 11.69Mb

There was 1 failure:

1) TobiasGies\HHVMCompatibilityTest::testCreateDOMDocumentWithDisabledConstructor
Failed asserting that '__PHP_Unserializable_Class' is not equal to <string:__PHP_Unserializable_Class>.

/home/tobias/sources/playground/HHVMCompatibilityTest.php:20

FAILURES!
Tests: 2, Assertions: 3, Failures: 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment