/** * executed before each test */ public function _before() { $this->markTestSkipped('Mocking up php functions doesnt work for zephir extensions.'); $_FILES = ['photo' => ['name' => ['f0', 'f1', ['f2', 'f3'], [[[['f4']]]]], 'type' => ['text/plain', 'text/csv', ['image/png', 'image/jpeg'], [[[['application/octet-stream']]]]], 'tmp_name' => ['t0', 't1', ['t2', 't3'], [[[['t4']]]]], 'error' => [0, 0, [0, 0], [[[[8]]]]], 'size' => [10, 20, [30, 40], [[[[50]]]]]]]; $request = new Request(); $request->setDI($this->tester->getApplication()->getDI()); $uploadedFiles = $request->getUploadedFiles(); $files = []; /** @var Request\File $file */ foreach ($uploadedFiles as $file) { $files[] = ['name' => $file->getName(), 'tmp_name' => $file->getTempName(), 'type' => $file->getType(), 'size' => $file->getSize(), 'error' => $file->getError()]; } $this->files = $files; Test::func('Phalcon\\Validation\\Validator', 'getimagesize', function ($tmpName) { $tmpSizes = ['t0' => null, 't1' => null, 't2' => [500, 500], 't3' => [1000, 1000], 't4' => null]; return $tmpSizes[$tmpName]; }); Test::func('Phalcon\\Validation\\Validator', 'finfo_open', function ($mimeType) { return null; }); Test::func('Phalcon\\Validation\\Validator', 'finfo_file', function ($tmp, $tmpName) { $tmpTypes = ['t0' => 'text/plain', 't1' => 'text/csv', 't2' => 'image/png', 't3' => 'image/jpeg', 't4' => 'application/octet-stream']; return $tmpTypes[$tmpName]; }); Test::func('Phalcon\\Validation\\Validator', 'is_uploaded_file', function ($tmpName) { return true; }); Test::func('Phalcon\\Validation\\Validator', 'finfo_close', function ($tmp, $tmpName) { }); $_SERVER["REQUEST_METHOD"] = "POST"; }
protected function _before() { $_SERVER = array_merge($_SERVER, ['HTTP_HOST' => 'localhost', 'SERVER_PORT' => '80', 'REQUEST_URI' => '/test']); //Mocking mkdir() test::func('nlac', 'mkdir', function ($dir = '') { }); }
protected function setUp() { $this->out = fopen('php://memory', 'w'); $this->listener = new TestListener($this->out); // mock standard php functions output AspectMock\Test::func('PHPUnit\\TeamCity', 'date', '2015-05-28T16:14:12.17+0700'); AspectMock\Test::func('PHPUnit\\TeamCity', 'getmypid', 24107); }
public function testFailedVerification() { $this->setExpectedException('PHPUnit_Framework_ExpectationFailedException'); $func = test::func('demo', 'strlen', function () { return 10; }); expect(strlen('hello'))->equals(10); $func->verifyNeverInvoked('strlen'); }
public function testCall() { $request = $this->prepareRequest(); // check if curl is not installed test::func('esia', 'curl_init', false); $response = $request->call('stub'); $this->assertNull($response); // check if correct call test::clean(); test::func('esia', 'curl_exec', '{}'); $response = $request->call('stub'); $this->assertTrue($response instanceof \stdClass); }
public function testSignPKCS7() { $openId = $this->prepareOpenId(); $checkException = function ($func, $expectedCode) use($openId) { try { test::func('esia', $func, false); $openId = $this->prepareOpenId(); $openId->signPKCS7('message'); $errorMessage = sprintf('Exception %s isn\'t rise with code %d', SignFailException::class, $expectedCode); $this->fail($errorMessage); } catch (SignFailException $e) { $message = 'Exception rise with wrong code'; $this->assertEquals($e->getCode(), $expectedCode, $message); } test::clean(); }; $checkException('openssl_x509_read', SignFailException::CODE_CANT_READ_CERT); $checkException('openssl_pkey_get_private', SignFailException::CODE_CANT_READ_PRIVATE_KEY); $checkException('openssl_pkcs7_sign', SignFailException::CODE_SIGN_FAIL); // check correct call $result = $openId->signPKCS7('message'); $this->assertInternalType('string', $result); }