Skip to content

Instantly share code, notes, and snippets.

@MarcosLoureiro
Created June 25, 2013 10:36
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 MarcosLoureiro/df5821e536cc5492ffb6 to your computer and use it in GitHub Desktop.
Save MarcosLoureiro/df5821e536cc5492ffb6 to your computer and use it in GitHub Desktop.
Script for testing issues EZP-21055 and EZP-20952
<?php
namespace test\QABundle\Controller;
use eZ\Bundle\EzPublishCoreBundle\Controller;
class DefaultController extends Controller
{
/**
* repo
*/
protected $repo;
public function indexAction($name)
{
echo "<pre>";
$this->testTC1695Ezp21055();
echo "</pre>";
return $this->render('testQABundle:Default:index.html.twig', array('name' => $name));
}
function testTC1695Ezp21055()
{
$this->repo = $this->getRepository();
$this->repo->setCurrentUser( $this->repo->getUserService()->loadUserByCredentials( "admin" , "publish" ) );
// get services
$contentService = $this->repo->getContentService();
$locationService = $this->repo->getLocationService();
$contentTypeService = $this->repo->getContentTypeService();
$initial = memory_get_usage();
echo "Initial memory value: {$initial}\n";
echo "Memory | before | draft | publish | after | delta\n";
echo "--------------------------------------------------------------------\n";
for( $i=0 ; $i < 10 ; $i ++ )
{
echo "Iteration: {$i} | ";
// before
$before = memory_get_usage();
echo $before . " | ";
//set initial vars for content create
$contentType = $contentTypeService->loadContentTypeByIdentifier( 'folder' );
$contentSkeleton = $contentService->newContentCreateStruct( $contentType, 'eng-GB' );
$contentSkeleton->setField( 'name', 'Folder '. $i );
$locationCreateStruct = $locationService->newLocationCreateStruct( 2 );
// draft
$draft = $contentService->createContent( $contentSkeleton, array( $locationCreateStruct ) );
echo memory_get_usage() . " | ";
// publish
$content = $contentService->publishVersion( $draft->versionInfo );
echo memory_get_usage() . " | ";
// unset any possible memory
unset( $content );
unset( $draft );
unset( $locationCreateStruct );
unset( $contentSkeleton );
unset( $contentType );
// clear the cache
\eZContentObject::clearCache();
// after cleaning
echo memory_get_usage() . " | ";
// get the Delta
$after = memory_get_usage() ;
$delta = $after - $before;
echo $delta . "\n";
}
echo "--------------------------------------------------------------------\n";
echo "Memory lost in last iteration: {$delta}\n";
// assert value
if ( $delta > 0 )
{
$this->fail( "Memory lost in last iteration should be '0' it is: {$delta}\n" );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment