Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HttpTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\Filesystem\Driver\Http;
10 
11 class HttpTest extends \PHPUnit\Framework\TestCase
12 {
14  public static $headers;
15 
17  public static $fileGetContents;
18 
20  public static $filePutContents;
21 
23  public static $fsockopen;
24 
25  protected function setUp()
26  {
27  require_once __DIR__ . '/../_files/http_mock.php';
28 
29  self::$headers = [];
30  self::$fileGetContents = '';
31  self::$filePutContents = true;
32  self::$fsockopen = true;
33  }
34 
38  public function testIsExists($status, $result)
39  {
40  self::$headers = [$status];
41  $this->assertEquals($result, (new Http())->isExists(''));
42  }
43 
47  public function dataProviderForTestIsExists()
48  {
49  return [['200 OK', true], ['404 Not Found', false]];
50  }
51 
55  public function testStat($headers, $result)
56  {
57  self::$headers = $headers;
58  $this->assertEquals($result, (new Http())->stat(''));
59  }
60 
64  public function dataProviderForTestStat()
65  {
66  $headers1 = [
67  'Content-Length' => 128,
68  'Content-Type' => 'type',
69  'Last-Modified' => '2013-12-19T17:41:45+00:00',
70  'Content-Disposition' => 1024,
71  ];
72 
73  $result1 = $this->_resultForStat(
74  ['size' => 128, 'type' => 'type', 'mtime' => '2013-12-19T17:41:45+00:00', 'disposition' => 1024]
75  );
76 
77  return [[[], $this->_resultForStat()], [$headers1, $result1]];
78  }
79 
86  protected function _resultForStat($nonEmptyValues = [])
87  {
88  $result = [
89  'dev' => 0,
90  'ino' => 0,
91  'mode' => 0,
92  'nlink' => 0,
93  'uid' => 0,
94  'gid' => 0,
95  'rdev' => 0,
96  'atime' => 0,
97  'ctime' => 0,
98  'blksize' => 0,
99  'blocks' => 0,
100  'size' => 0,
101  'type' => '',
102  'mtime' => 0,
103  'disposition' => null,
104  ];
105 
106  return array_merge($result, $nonEmptyValues);
107  }
108 
109  public function testFileGetContents()
110  {
111  $content = 'some content';
112  self::$fileGetContents = $content;
113  $this->assertEquals($content, (new Http())->fileGetContents(''));
114  }
115 
117  {
118  $content = '';
119  self::$fileGetContents = '';
120  $this->assertEquals($content, (new Http())->fileGetContents(''));
121  }
122 
123  public function testFilePutContents()
124  {
125  self::$filePutContents = true;
126  $this->assertTrue((new Http())->filePutContents('', ''));
127  }
128 
132  public function testFilePutContentsFail()
133  {
134  self::$filePutContents = false;
135  (new Http())->filePutContents('', '');
136  }
137 
142  public function testFileOpenInvalidUrl()
143  {
144  (new Http())->fileOpen('', '');
145  }
146 
147  public function testFileOpen()
148  {
149  $fsockopenResult = 'resource';
150  self::$fsockopen = $fsockopenResult;
151  $this->assertEquals($fsockopenResult, (new Http())->fileOpen('example.com', 'r'));
152  }
153 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$status
Definition: order_status.php:8