Skip to content

Instantly share code, notes, and snippets.

View azakordonets's full-sized avatar

Andrew Zakordonets azakordonets

View GitHub Profile
@azakordonets
azakordonets / getPrivateProperty.php
Created February 11, 2014 15:10
Get private property from instance of the class
private function getProtectedProperty($class, $propertyName)
{
$reflectObj = new \ReflectionObject($class);
$extensions = $reflectObj->getProperty($propertyName);
$extensions->setAccessible(true);
return $extensions->getValue($class);
}
@azakordonets
azakordonets / setPrivateProperty.php
Created February 20, 2014 08:42
SetPrivateProperty.php
private function setProtectedProperty($class, $propertyName, $setValue)
{
$reflectObj = new \ReflectionObject($class);
$extensions = $reflectObj->getProperty($propertyName);
$extensions->setAccessible(true);
$extensions->setValue($class, $setValue);
}
@azakordonets
azakordonets / runProtectedMethod.php
Last active August 29, 2015 13:56
runProtectedMethod
protected function runProtectedFunction($class, $methodName, $args = null)
{
$reflectMethod = new \ReflectionMethod($class,$methodName);
$reflectMethod->setAccessible(true);
if ($args == null)
{
return $reflectMethod->invoke($class);
} else
{
return $reflectMethod->invokeArgs($class, $args);
@azakordonets
azakordonets / RandomInt.java
Created March 14, 2014 09:27
Generate random int number in Java
/**
* Random generator in range
*
* @param minimum Number
* @param maximum Number
* @return randomNumber
*/
public int randomGenerator(int minimum, int maximum) {
Random rn = new Random();
int range = maximum - minimum + 1;
@azakordonets
azakordonets / IgnorePhpUnitTest.php
Created April 15, 2014 13:21
This call makes phpunit to mute specific test
$this->markTestSkipped('This test is scipped ');
@azakordonets
azakordonets / DbConnection.java
Created April 18, 2014 12:08
Class for DbConnection handiling
package Base.db_connection;
import org.json.JSONObject;
import java.sql.*;
import static Base.TestPropertiesLoader.getDbConnectionDetails;
public class DbConnection {
public Connection con = null;
@azakordonets
azakordonets / ProxySelector.java
Created April 18, 2014 12:18
This class allows you to get a hacky but working way of connecting with Java to SOCKS proxy, when standart ways are not working. Java has a problem with DNS resolving and therefore i had an issue with one of my project. When i was enabling proxy setting through System.Properties , i still was hitting production server, not the test server behind…
import java.net.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.IOException;
/**
* this class is needed for Java to connect to SOCKS proxy server
* Unfortunately Java cannot resolve remote DNS and therefore, when we set System.properties
* with our proxy server details, we hit incorrect server . This is because
* Java is connecting to Proxy, but DNS is resolving with system details and therefore goes to server directly.
@azakordonets
azakordonets / yaml_to_json_convertor.py
Created April 30, 2014 09:50
Converty yaml to json on Python
import yaml
import json
yml = "file_path"
data = yaml.load(open(yml,'r'))
json = json.dumps(data)
print(json)
@azakordonets
azakordonets / getJSONFromFile.java
Created May 6, 2014 14:33
This method allows you to read from file (where already stored data in json format) and save it into JSON object.
public static JSONObject getJSONFromFile(String path) throws JSONException, IOException, ParseException {
JSONParser parser = new JSONParser();
Object obj = parser.parse(new FileReader(path));
return new JSONObject(obj.toString());
}
@azakordonets
azakordonets / webDriverSnippets.java
Last active August 29, 2015 14:01
Set of handy commands and method to work with WebDriver
public void refreshPage(){
driver.navigate().refresh();
}