Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- add info_dump.phpt test that tests meminfo_info_dump function #27

Merged
merged 1 commit into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions extension/tests/fixture/book.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
]>
<book id="listing">
<title>My lists</title>
<chapter id="books">
<title>My books</title>
<para>
<informaltable>
<tgroup cols="4">
<thead>
<row>
<entry>Title</entry>
<entry>Author</entry>
<entry>Language</entry>
<entry>ISBN</entry>
</row>
</thead>
<tbody>
<row>
<entry>The Grapes of Wrath</entry>
<entry>John Steinbeck</entry>
<entry>en</entry>
<entry>0140186409</entry>
</row>
<row>
<entry>The Pearl</entry>
<entry>John Steinbeck</entry>
<entry>en</entry>
<entry>014017737X</entry>
</row>
<row>
<entry>Samarcande</entry>
<entry>Amine Maalouf</entry>
<entry>fr</entry>
<entry>2253051209</entry>
</row>
<!-- TODO: I have a lot of remaining books to add.. -->
</tbody>
</tgroup>
</informaltable>
</para>
</chapter>
</book>
112 changes: 112 additions & 0 deletions extension/tests/info_dump.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
--TEST--
meminfo_objects_list with some objects
--FILE--
<?php
$docTest = new DOMDocument();
$docTest->load(__DIR__.'/fixture/book.xml');

$rFilePointer = fopen('php://memory', 'rw');

$arrayTest = [
'itemBool' => true,
'itemInteger' => 23,
'itemDoubles' => 1.2e3,
'itemNull' => null,
'itemString' => 'hello',
'itemObject' => $docTest,
'itemArray' => (array) $docTest,
'itemResource' => $rFilePointer,
];

meminfo_info_dump($rFilePointer);

rewind($rFilePointer);
$jsonO = json_decode(stream_get_contents($rFilePointer), true);
fclose($rFilePointer);
if (is_array($jsonO)) {
$items = $jsonO['items'];
printf(
"meminfo_info_dump JSON decode ok\nz_val_count:%d\n",
count($items)
);
uasort($items, function ($itemA, $itemB) {
return $itemA['type'] > $itemB['type']
|| ($itemA['type'] == $itemB['type'] && $itemA['size'] > $itemB['size']);
});

foreach($items as $item){
printf(
"item type:%s size:%d\n",
$item['type'],
$item['size']
);
}
} else {
echo 'meminfo_info_dump JSON decode fail';
}
?>
--EXPECT--
meminfo_info_dump JSON decode ok
z_val_count:62
item type:array size:96
item type:array size:96
item type:array size:96
item type:array size:96
item type:array size:96
item type:array size:96
item type:array size:96
item type:array size:96
item type:boolean size:24
item type:boolean size:24
item type:boolean size:24
item type:boolean size:24
item type:boolean size:24
item type:boolean size:24
item type:boolean size:24
item type:boolean size:24
item type:boolean size:24
item type:boolean size:24
item type:double size:24
item type:double size:24
item type:integer size:24
item type:integer size:24
item type:integer size:24
item type:integer size:24
item type:null size:24
item type:null size:24
item type:null size:24
item type:null size:24
item type:null size:24
item type:null size:24
item type:null size:24
item type:null size:24
item type:null size:24
item type:object size:56
item type:resource size:24
item type:string size:24
item type:string size:24
item type:string size:25
item type:string size:25
item type:string size:25
item type:string size:25
item type:string size:27
item type:string size:27
item type:string size:27
item type:string size:29
item type:string size:29
item type:string size:29
item type:string size:29
item type:string size:33
item type:string size:37
item type:string size:46
item type:string size:64
item type:string size:64
item type:string size:64
item type:string size:84
item type:string size:84
item type:string size:84
item type:string size:84
item type:string size:84
item type:string size:87
item type:string size:87
item type:string size:1054
37 changes: 37 additions & 0 deletions extension/tests/info_dump_memory-leak.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
meminfo_objects_list with some objects
--FILE--
<?php
$docTest = new DOMDocument();
$docTest->load(__DIR__.'/fixture/book.xml');

$rFilePointer = fopen('/dev/null', 'rw');

$arrayTest = [
'itemBool' => true,
'itemInteger' => 23,
'itemDoubles' => 1.2e3,
'itemNull' => null,
'itemString' => 'hello',
'itemObject' => $docTest,
'itemArray' => (array) $docTest,
'itemResource' => $rFilePointer,
];
$attemptCount = 1000;
gc_collect_cycles();
$startM = memory_get_usage(true);
while ($attemptCount-- > 0) {
meminfo_info_dump($rFilePointer);
}
fclose($rFilePointer);
gc_collect_cycles();
$endM = memory_get_usage(true);
if ($endM / $startM < 2) {
echo 'Memory leak test was successful';
} else {
echo "Memory leak test was failed\n";
printf("Memory leak:%s bytes",$endM - $startM);
}
?>
--EXPECT--
Memory leak test was successful