Skip to content

Instantly share code, notes, and snippets.

View spolischook's full-sized avatar
🌐
Saving the world

Serhii Polishchuk spolischook

🌐
Saving the world
View GitHub Profile
@spolischook
spolischook / kotoblog_53e7bd8212592.php
Last active August 29, 2015 14:05
Get annotation from class
<?php
require __DIR__ . '/../vendor/autoload.php';
use Doctrine\Common\Annotations\AnnotationReader;
require __DIR__ . '/../src/Kotoblog/Annotation/Mapping.php';
$annotationReader = new AnnotationReader();
$reflectionClass = new ReflectionClass('\\Kotoblog\\Entity\\Blogpost');
@spolischook
spolischook / kotoblog_53f026f4e1518.php
Last active August 29, 2015 14:05
Load Doctrine fixtures from Controller
<?php
//....
public function indexAction()
{
$application = new Application($this->get('kernel'));
$application->add(new CreateSchemaDoctrineCommand());
$command = $application->find('doctrine:schema:create');
@spolischook
spolischook / kotoblog_53f028c2c1943.php
Last active August 29, 2015 14:05
How to dump asserts for Entity/Document in Symfony2
<?php
$user = new User();
/** @var \Symfony\Component\Validator\Mapping\ClassMetadataFactory $metadataFactory */
$metadataFactory = $this->get('validator.mapping.class_metadata_factory');
$metadata = $metadataFactory->getMetadataFor($user);
$constraints = [];
echo "Constraints:";
foreach ($metadata->properties as $property) {
@spolischook
spolischook / kotoblog_53f0712fa71e6.json
Last active August 29, 2015 14:05
Composer no matching package found fix
{
"require": {
"behat/behat": ">=2.4@stable",
"behat/mink": "1.4@stable",
"behat/mink-extension": "*",
"behat/mink-goutte-driver": "*"
},
"minimum-stability": "dev",
{# ... #}
{{app.kernel.cachedir}}
{{app.kernel.logdir}}
{{app.kernel.rootdir}}
{{app.request.basepath}}
{{app.request.baseurl}}
{{app.request.uri}}
{{app.security.token.user}}
{{app.session.locale}}
{# ... #}
@spolischook
spolischook / kotoblog_behat-mink-symfony-2-1.json
Last active August 29, 2015 14:05
Behat + Mink + Symfony 2.1
{
"require-dev": {
"behat/behat": "@dev",
"behat/mink": "@dev",
"behat/symfony2-extension": "dev-master",
"behat/mink-extension": "*",
"behat/mink-selenium2-driver": "dev-master",
"behat/mink-browserkit-driver": "dev-master",
"behat/mink-sahi-driver": "@dev"
}
@spolischook
spolischook / kotoblog_behat-mink-symfony-2-1.yml
Last active August 29, 2015 14:05
Behat.yml for symfony2
default:
extensions:
Behat\Symfony2Extension\Extension:
mink_driver: true
Behat\MinkExtension\Extension:
default_session: 'symfony2'
@spolischook
spolischook / kotoblog_53f07b8b29dc0.bash
Last active August 29, 2015 14:05
Install/reinstall phpUnit on Ubuntu
sudo apt-get remove phpunit
sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
sudo pear update-channels
sudo pear upgrade-all
sudo pear install --alldeps phpunit/PHPUnit sudo pear install --force --alldeps pear.phpunit.de/PHPUnit
@spolischook
spolischook / base_script.php
Created September 23, 2014 14:20
Base script for CLI scripts
<?php
function show_run($text, $command, $canFail = false)
{
echo "\n* $text\n$command\n";
passthru($command, $return);
if (0 !== $return && !$canFail) {
echo "\n/!\\ The command returned $return\n";
exit(1);
@spolischook
spolischook / importdb
Created September 23, 2014 14:20
Batch script for import mongo dump
#!/usr/bin/env php
<?php
require_once __DIR__.'/base_script.php';
$options = getopt("", array('db:', 'dir:'));
$options['dir'] = !empty($options['dir']) ? $options['dir'] : "/";
$options['db'] = !empty($options['db']) ? $options['db']: "exercise";
$optionsLine = sprintf(" --dir=%s --db=%s", $options['dir'], $options['db']);