PHP code example of crimsonkissaki / mockmaker
1. Go to this page and download the library: Download crimsonkissaki/mockmaker library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
crimsonkissaki / mockmaker example snippets
use MockMaker\MockMaker;
$mocks = new MockMaker();
// @param string|array $files Fully qualified file paths
$mocks->mockTheseEntities($files);
// @param string|array $dirs Fully qualified directory paths
$mocks->mockEntitiesInDirectory($dirs);
$mocks->recursively();
// @param string $path Fully qualified path to your project's root directory
$mocks->setProjectRootPath($path);
// @param string $dir Fully qualified directory path
$mocks->saveMockFilesIn($dir);
// @param string $dir Fully qualified directory path
$mocks->createUnitTests();
// @param string $dir Fully qualified directory path
$mocks->saveUnitTestsIn($dir);
$mocks->ignoreDirectoryStructure();
$mocks->overwriteMockFiles();
$mocks->overwriteUnitTestFiles();
// @param string $regex Regex pattern
$mocks->excludeFilesWithFormat($regex);
// @param string $regex Regex pattern
$mocks->
// @param string $format Format for mock file names and class names
$mocks->saveMocksWithFileNameFormat($format);
// @param string $namespace Base namespace to use for mocks
$mocks->useBaseNamespaceForMocks($namespace);
// @return ConfigData
$mocks->verifySettings();
// @return array
$mocks->testRegexPatterns();
// @return string
$mocks->createMocks();
use MockMaker\MockMaker;
$rootDir = '/Applications/XAMPP/xamppfiles/htdocs/yourproject/src/';
$projectDir = $rootDir . 'Project/Bundle/MyAwesomeBundle/';
$mm = new MockMaker();
$code = $mm->mockTheseEntities($projectDir . 'Entity/TestEntity.php')
->createMocks();
echo $code;
use MockMaker\MockMaker;
$rootDir = '/Applications/XAMPP/xamppfiles/htdocs/yourproject/src/';
$projectDir = $rootDir . 'Project/Bundle/MyAwesomeBundle/';
$mm = new MockMaker();
$mm->mockEntitiesInDirectory($projectDir . 'Entity')
->recursively()
->exclude('/Repository$/')
->saveMockFilesIn($projectDir . 'Tests/Mocks/Entity')
->saveUnitTestsIn($projectDir . 'Tests/Mocks/EntityTests')
->overwriteMockFiles()
->overwriteUnitTestFiles()
->createMocks();
return array(
'propertyName' => 'propertyName value',
'propertyName2' => 'John Q. Public',
'propertyName3' => new \stdClass(),
'propertyName4' => new SimpleEntity(),
);
use Path\To\EntityMock;
$mock = EntityMock::getMock();
use Path\To\EntityMock;
use Path\To\CustomerEntityMock;
// format is 'propertyName' => 'desiredValue'
$properties = array(
'customerOrders', // no defined value, defaultly assigned NULL
'customerId' => 1,
'customerName' => 'John Doe',
'customerData' => CustomerEntityMock::getMock()
);
$mock = EntityMock::getMock( $properties );
use Path\To\EntityMock;
use Path\To\CustomerEntityMock;
// format is 'propertyName' => 'desiredValue'
$properties = array(
'customerOrders',
'customerId' => 1,
'customerName' => 'John Doe',
'customerData' => CustomerEntityMock::getMock()
);
$ignore = array( 'customerOrders', 'customerPhone', 'disabledOn' );
$mock = EntityMock::getMock( $properties, $ignore );