Skip to content

Instantly share code, notes, and snippets.

@romansklenar
Created December 11, 2009 21:42
Show Gist options
  • Save romansklenar/254541 to your computer and use it in GitHub Desktop.
Save romansklenar/254541 to your computer and use it in GitHub Desktop.
Ruby on Rails Inflector port to PHP
<?php
/**
* The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without, and class names to foreign keys.
* This solution is partitionaly based on Ruby on Rails ActiveSupport::Inflector (c) David Heinemeier Hansson. (http://rubyonrails.org), MIT license
* @see http://api.rubyonrails.org/classes/Inflector.html
*
* @author Roman Sklenář
* @copyright Copyright (c) 2009 Roman Sklenář (http://romansklenar.cz)
* @copyright Copyright (c) 2008 Luke Baker (http://lukebaker.org)
* @copyright Copyright (c) 2005 Flinn Mueller (http://actsasflinn.com)
* @license New BSD License
* @example http://addons.nettephp.com/inflector
* @package Nette\Extras\Inflector
* @version 0.5
*/
class Inflector {
/** @var array of singular nouns as rule => replacement */
public static $singulars = array(
'/(quiz)$/i' => '\1zes',
'/^(ox)$/i' => '\1en',
'/([m|l])ouse$/i' => '\1ice',
'/(matr|vert|ind)(?:ix|ex)$/i' => '\1ices',
'/(x|ch|ss|sh)$/i' => '\1es',
'/([^aeiouy]|qu)y$/i' => '\1ies',
'/(hive)$/i' => '\1s',
'/(?:([^f])fe|([lr])f)$/i' => '\1\2ves',
'/sis$/i' => 'ses',
'/([ti])um$/i' => '\1a',
'/(buffal|tomat)o$/i' => '\1oes',
'/(bu)s$/i' => '\1ses',
'/(alias|status)$/i' => '\1es',
'/(octop|vir)us$/i' => '\1i',
'/(ax|test)is$/i' => '\1es',
'/s$/i' => 's',
'/$/' => 's',
);
/** @var array of plural nouns as rule => replacement */
public static $plurals = array(
'/(database)s$/i' => '\1',
'/(quiz)zes$/i' => '\1',
'/(matr)ices$/i' => '\1ix',
'/(vert|ind)ices$/i' => '\1ex',
'/^(ox)en/i' => '\1',
'/(alias|status)es$/i' => '\1',
'/(octop|vir)i$/i' => '\1us',
'/(cris|ax|test)es$/i' => '\1is',
'/(shoe)s$/i' => '\1',
'/(o)es$/i' => '\1',
'/(bus)es$/i' => '\1',
'/([m|l])ice$/i' => '\1ouse',
'/(x|ch|ss|sh)es$/i' => '\1',
'/(m)ovies$/i' => '\1ovie',
'/(s)eries$/i' => '\1eries',
'/([^aeiouy]|qu)ies$/i' => '\1y',
'/([lr])ves$/i' => '\1f',
'/(tive)s$/i' => '\1',
'/(hive)s$/i' => '\1',
'/([^f])ves$/i' => '\1fe',
'/(^analy)ses$/i' => '\1sis',
'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
'/([ti])a$/i' => '\1um',
'/(n)ews$/i' => '\1ews',
'/s$/i' => '',
);
/** @var array of irregular nouns */
public static $irregular = array(
'person' => 'people',
'man' => 'men',
'child' => 'children',
'sex' => 'sexes',
'move' => 'moves',
'cow' => 'kine',
);
/** @var array of uncountable nouns */
public static $uncountable = array(
'equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep',
);
/** @var bool use Ruby on Rails ActiveRecord naming conventions? */
public static $railsStyle = FALSE;
/**
* The reverse of pluralize, returns the singular form of a word.
*
* @param string $word
* @return string
*/
public static function singularize($word) {
$lower = /*Nette\*/String::lower($word);
if (self::isSingular($word))
return $word;
if (!self::isCountable($word))
return $word;
if (self::isIrregular($word))
foreach (self::$irregular as $single => $plural)
if ($lower == $plural)
return $single;
foreach (self::$plurals as $rule => $replacement)
if (preg_match($rule, $word))
return preg_replace($rule, $replacement, $word);
return FALSE;
}
/**
* Returns the plural form of the word.
*
* @param string $word
* @return string
*/
public static function pluralize($word) {
$lower = /*Nette\*/String::lower($word);
if (self::isPlural($word))
return $word;
if (!self::isCountable($word))
return $word;
if (self::isIrregular($word))
return self::$irregular[$lower];
foreach (self::$singulars as $rule => $replacement)
if (preg_match($rule, $word))
return preg_replace($rule, $replacement, $word);
return FALSE;
}
/**
* Is given string singular noun?
*
* @param string $word
* @return bool
*/
public static function isSingular($word) {
if (!self::isCountable($word))
return TRUE;
return !self::isPlural($word);
}
/**
* Is given string plural noun?
*
* @param string $word
* @return bool
*/
public static function isPlural($word) {
$lower = /*Nette\*/String::lower($word);
if (!self::isCountable($word))
return TRUE;
if (self::isIrregular($word))
return in_array($lower, array_values(self::$irregular));
foreach (self::$plurals as $rule => $replacement)
if (preg_match($rule, $word))
return TRUE;
return FALSE;
}
/**
* Is given string countable noun?
*
* @param string $word
* @return bool
*/
public static function isCountable($word) {
$lower = /*Nette\*/String::lower($word);
return (bool) !in_array($lower, self::$uncountable);
}
/**
* Is given string irregular noun?
*
* @param string $word
* @return bool
*/
public static function isIrregular($word) {
$lower = /*Nette\*/String::lower($word);
return (bool) in_array($lower, self::$irregular) || array_key_exists($lower, self::$irregular);
}
/**
* Ordinalize turns a number into an ordinal string used to denote
* the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
*
* @param int $number
* @return string
*/
public static function ordinalize($number) {
$number = (int) $number;
if ($number % 100 >= 11 && $number % 100 <= 13)
return "{$number}th";
else
switch ($number % 10) {
case 1: return "{$number}st";
case 2: return "{$number}nd";
case 3: return "{$number}rd";
default: return "{$number}th";
}
}
/**
* By default, camelize() converts strings to UpperCamelCase.
* If the second argument is set to FALSE then camelize() produces lowerCamelCase.
* camelize() will also convert '/' to '\' which is useful for converting paths to namespaces.
*
* @param string $word lower case and underscored word
* @param bool $firstUpper first letter in uppercase?
* @return string
*/
public static function camelize($word, $firstUpper = TRUE) {
$word = preg_replace(array('/(^|_)(.)/e', '/(\/)(.)/e'), array("strtoupper('\\2')", "strtoupper('\\2')"), strval($word));
return $firstUpper ? ucfirst($word) : lcfirst($word);
}
/**
* Replaces underscores with dashes in the string.
*
* @param string $word underscored word
* @return string
*/
public static function dasherize($word) {
return preg_replace('/_/', '-', strval($word));
}
/**
* Capitalizes all the words and replaces some characters in the string to create a nicer looking title.
* Titleize() is meant for creating pretty output.
*
* @param string $word underscored word
* @return string
*/
public static function titleize($word) {
return preg_replace(array("/\b('?[a-z])/e"), array("ucfirst('\\1')"), self::humanize(self::underscore($word)));
}
/**
* The reverse of camelize(). Makes an underscored form from the expression in the string.
* Changes '::' to '/' to convert namespaces to paths.
*
* @param string $word camel cased word
* @return string
*/
public static function underscore($word) {
return strtolower(preg_replace('/([A-Z]+)([A-Z])/','\1_\2', preg_replace('/([a-z\d])([A-Z])/','\1_\2', $word)));
}
/**
* Capitalizes the first word and turns underscores into spaces and strips _id.
* Like titleize(), this is meant for creating pretty output.
*
* @param string $word lower case and underscored word
* @return string
*/
public static function humanize($word) {
return ucfirst(strtolower(preg_replace(array('/_id$/', '/_/'), array('', ' '), $word)));
}
/**
* Removes the namespace part from the expression in the string.
*
* @param string|object $class class name in namespace
* @return string
*/
public static function demodulize($class) {
$class = ltrim(strval($class), '\\');
if ($a = strrpos($class, '\\'))
$class = substr($class, $a+1);
return preg_replace('/^.*::/', '', $class);
}
/**
* Create the name of a table like Rails does for models to table names.
* This method uses the pluralize method on the last word in the string.
*
* @param string $class class name
* @return string
*/
public static function tableize($class) {
$class = substr_count($class, 'Model', 1) ? preg_replace('/Model$/', '', $class) : $class;
$table = self::pluralize($class);
return self::$railsStyle ? self::underscore($table) : self::camelize($table);
}
/**
* Create a class name from a plural table name like Rails does for table names to models.
* Note that this returns a string and not a Class.
* To convert to an actual class follow classify() with constantize().
*
* @param string $table table name
* @return string
*/
public static function classify($table) {
return self::camelize(self::singularize($table));
}
/**
* Creates a foreign key name from a class name.
* Second parametr sets whether the method should put '_' between the name and 'id'/'Id'.
*
* @param string $class class name
* @return string
*/
public static function foreignKey($class) {
return self::underscore((self::isPlural($class) ? self::singularize($class) : self::demodulize($class))) . (self::$railsStyle ? "_id" : "Id");
}
/**
* Create a name of intersect entity of M:N relation of given tables.
*
* @param string $local
* @param string $referenced
* @return string
*/
public static function intersectEntity($local, $referenced) {
return self::tableize(self::demodulize($local)) . (self::$railsStyle ? '_' : '') . self::tableize(self::demodulize($referenced));
}
}
<?php
require_once 'PHPUnit/Framework.php';
/**
* Test class for Inflector.
*/
class InflectorTest extends PHPUnit_Framework_TestCase {
public function testPluralize() {
$this->assertSame('dogs', Inflector::pluralize('dog'));
$this->assertSame('Dogs', Inflector::pluralize('Dog'));
$this->assertSame('DOGs', Inflector::pluralize('DOG'));
$this->assertSame('quizzes', Inflector::pluralize('quiz'));
$this->assertSame('tomatoes', Inflector::pluralize('tomato'));
$this->assertSame('mice', Inflector::pluralize('mouse'));
$this->assertSame('people', Inflector::pluralize('person'));
$this->assertSame('equipment', Inflector::pluralize('equipment'));
$this->assertSame('companies', Inflector::pluralize('company'));
$this->assertSame('dogs', Inflector::pluralize('dogs'));
$this->assertSame('Dogs', Inflector::pluralize('Dogs'));
$this->assertSame('DOGs', Inflector::pluralize('DOGs'));
$this->assertSame('quizzes', Inflector::pluralize('quizzes'));
$this->assertSame('tomatoes', Inflector::pluralize('tomatoes'));
$this->assertSame('mice', Inflector::pluralize('mice'));
$this->assertSame('people', Inflector::pluralize('people'));
$this->assertSame('equipment', Inflector::pluralize('equipment'));
$this->assertSame('companies', Inflector::pluralize('companies'));
}
public function testSingularize() {
$this->assertSame('dog', Inflector::singularize('dogs'));
$this->assertSame('Dog', Inflector::singularize('Dogs'));
$this->assertSame('DOG', Inflector::singularize('DOGS'));
$this->assertSame('quiz', Inflector::singularize('quizzes'));
$this->assertSame('tomato', Inflector::singularize('tomatoes'));
$this->assertSame('mouse', Inflector::singularize('mice'));
$this->assertSame('person', Inflector::singularize('people'));
$this->assertSame('equipment', Inflector::singularize('equipment'));
$this->assertSame('company', Inflector::singularize('companies'));
$this->assertSame('dog', Inflector::singularize('dog'));
$this->assertSame('Dog', Inflector::singularize('Dog'));
$this->assertSame('DOG', Inflector::singularize('DOG'));
$this->assertSame('quiz', Inflector::singularize('quiz'));
$this->assertSame('tomato', Inflector::singularize('tomato'));
$this->assertSame('mouse', Inflector::singularize('mouse'));
$this->assertSame('person', Inflector::singularize('person'));
$this->assertSame('equipment', Inflector::singularize('equipment'));
$this->assertSame('company', Inflector::singularize('company'));
}
public function testIsPlural() {
$this->assertFalse(Inflector::isPlural('dog'));
$this->assertFalse(Inflector::isPlural('Dog'));
$this->assertFalse(Inflector::isPlural('DOG'));
$this->assertFalse(Inflector::isPlural('quiz'));
$this->assertFalse(Inflector::isPlural('tomato'));
$this->assertFalse(Inflector::isPlural('mouse'));
$this->assertFalse(Inflector::isPlural('person'));
$this->assertFalse(Inflector::isPlural('company'));
$this->assertTrue(Inflector::isPlural('dogs'));
$this->assertTrue(Inflector::isPlural('Dogs'));
$this->assertTrue(Inflector::isPlural('DOGS'));
$this->assertTrue(Inflector::isPlural('quizzes'));
$this->assertTrue(Inflector::isPlural('tomatoes'));
$this->assertTrue(Inflector::isPlural('mice'));
$this->assertTrue(Inflector::isPlural('people'));
$this->assertTrue(Inflector::isPlural('equipment'));
$this->assertTrue(Inflector::isPlural('companies'));
}
public function testIsSingular() {
$this->assertFalse(Inflector::isSingular('dogs'));
$this->assertFalse(Inflector::isSingular('Dogs'));
$this->assertFalse(Inflector::isSingular('DOGS'));
$this->assertFalse(Inflector::isSingular('quizzes'));
$this->assertFalse(Inflector::isSingular('tomatoes'));
$this->assertFalse(Inflector::isSingular('mice'));
$this->assertFalse(Inflector::isSingular('people'));
$this->assertFalse(Inflector::isSingular('companies'));
$this->assertTrue(Inflector::isSingular('dog'));
$this->assertTrue(Inflector::isSingular('Dog'));
$this->assertTrue(Inflector::isSingular('DOG'));
$this->assertTrue(Inflector::isSingular('quiz'));
$this->assertTrue(Inflector::isSingular('tomato'));
$this->assertTrue(Inflector::isSingular('mouse'));
$this->assertTrue(Inflector::isSingular('person'));
$this->assertTrue(Inflector::isSingular('equipment'));
$this->assertTrue(Inflector::isSingular('company'));
}
public function testIsCountable() {
$this->assertTrue(Inflector::isCountable('tomatoes'));
$this->assertFalse(Inflector::isCountable('equipment'));
}
public function testIsIrregular() {
$this->assertFalse(Inflector::isIrregular('dogs'));
$this->assertTrue(Inflector::isIrregular('person'));
}
public function testOrdinalize() {
$this->assertSame("0th", Inflector::ordinalize(0));
$this->assertSame("1st", Inflector::ordinalize(1));
$this->assertSame("2nd", Inflector::ordinalize(2));
$this->assertSame("3rd", Inflector::ordinalize(3));
$this->assertSame("4th", Inflector::ordinalize(4));
$this->assertSame("5th", Inflector::ordinalize(5));
$this->assertSame("10th", Inflector::ordinalize(10));
$this->assertSame("11th", Inflector::ordinalize(11));
$this->assertSame("12th", Inflector::ordinalize(12));
$this->assertSame("13th", Inflector::ordinalize(13));
$this->assertSame("14th", Inflector::ordinalize(14));
$this->assertSame("20th", Inflector::ordinalize(20));
$this->assertSame("21st", Inflector::ordinalize(21));
$this->assertSame("22nd", Inflector::ordinalize(22));
$this->assertSame("23rd", Inflector::ordinalize(23));
$this->assertSame("24th", Inflector::ordinalize(24));
$this->assertSame("25th", Inflector::ordinalize(25));
$this->assertSame("100th", Inflector::ordinalize(100));
$this->assertSame("101st", Inflector::ordinalize(101));
$this->assertSame("102nd", Inflector::ordinalize(102));
$this->assertSame("103rd", Inflector::ordinalize(103));
$this->assertSame("104th", Inflector::ordinalize(104));
$this->assertSame("105th", Inflector::ordinalize(105));
$this->assertSame("1000th", Inflector::ordinalize(1000));
$this->assertSame("1001st", Inflector::ordinalize(1001));
$this->assertSame("1002nd", Inflector::ordinalize(1002));
$this->assertSame("1003rd", Inflector::ordinalize(1003));
$this->assertSame("1004th", Inflector::ordinalize(1004));
$this->assertSame("1005th", Inflector::ordinalize(1005));
}
public function testHumanize() {
$this->assertSame("Employee salary", Inflector::humanize("employee_salary"));
$this->assertSame("Author", Inflector::humanize("author_id"));
}
public function testDemodulize() {
$this->assertSame("Order", Inflector::demodulize("\Admin\Models\Order"));
$this->assertSame("Order", Inflector::demodulize("Admin\Models\Order"));
$this->assertSame("Order", Inflector::demodulize("\Models\Order"));
$this->assertSame("Order", Inflector::demodulize("Models\Order"));
$this->assertSame("Order", Inflector::demodulize("\Order"));
$this->assertSame("Order", Inflector::demodulize("Order"));
}
public function testForeignKey() {
Inflector::$railsStyle = TRUE;
$this->assertSame("message_id", Inflector::foreignKey("\Front\Mailer\Message"));
$this->assertSame("post_id", Inflector::foreignKey("\Front\Blog\Post"));
$this->assertSame("user_id", Inflector::foreignKey("\Backend\User"));
$this->assertSame("message_id", Inflector::foreignKey("Front\Mailer\Message"));
$this->assertSame("post_id", Inflector::foreignKey("Front\Blog\Post"));
$this->assertSame("user_id", Inflector::foreignKey("Backend\User"));
$this->assertSame("message_id", Inflector::foreignKey("Message"));
$this->assertSame("post_id", Inflector::foreignKey("Post"));
$this->assertSame("user_id", Inflector::foreignKey("User"));
$this->assertSame("message_id", Inflector::foreignKey("Messages"));
$this->assertSame("post_id", Inflector::foreignKey("Posts"));
$this->assertSame("user_id", Inflector::foreignKey("Users"));
Inflector::$railsStyle = FALSE;
$this->assertSame("messageId", Inflector::foreignKey("\Front\Mailer\Message"));
$this->assertSame("postId", Inflector::foreignKey("\Front\Blog\Post"));
$this->assertSame("userId", Inflector::foreignKey("\Backend\User"));
$this->assertSame("messageId", Inflector::foreignKey("Front\Mailer\Message"));
$this->assertSame("postId", Inflector::foreignKey("Front\Blog\Post"));
$this->assertSame("userId", Inflector::foreignKey("Backend\User"));
$this->assertSame("messageId", Inflector::foreignKey("Message"));
$this->assertSame("postId", Inflector::foreignKey("Post"));
$this->assertSame("userId", Inflector::foreignKey("User"));
$this->assertSame("messageId", Inflector::foreignKey("Messages"));
$this->assertSame("postId", Inflector::foreignKey("Posts"));
$this->assertSame("userId", Inflector::foreignKey("Users"));
}
public function testIntersectEntity() {
Inflector::$railsStyle = TRUE;
$this->assertSame("messages_posts", Inflector::intersectEntity("\Front\Mailer\Message", "\Front\Blog\Post"));
$this->assertSame("messages_posts", Inflector::intersectEntity("\Front\Mailer\Messages", "\Front\Blog\Posts"));
$this->assertSame("posts_messages", Inflector::intersectEntity("\Front\Blog\Post", "\Front\Mailer\Message"));
$this->assertSame("posts_messages", Inflector::intersectEntity("\Front\Blog\Posts", "\Front\Mailer\Messages"));
$this->assertSame("users_messages", Inflector::intersectEntity("\Backend\User", "Front\Mailer\Message"));
$this->assertSame("users_messages", Inflector::intersectEntity("\Backend\Users", "Front\Mailer\Messages"));
$this->assertSame("posts_users", Inflector::intersectEntity("Front\Blog\Post", "Backend\User"));
$this->assertSame("posts_users", Inflector::intersectEntity("Front\Blog\Posts", "Backend\Users"));
$this->assertSame("messages_posts", Inflector::intersectEntity("Message", "Post"));
$this->assertSame("messages_posts", Inflector::intersectEntity("Messages", "Posts"));
$this->assertSame("users_messages", Inflector::intersectEntity("User", "Message"));
$this->assertSame("users_messages", Inflector::intersectEntity("Users", "Messages"));
$this->assertSame("posts_users", Inflector::intersectEntity("Post", "User"));
$this->assertSame("posts_users", Inflector::intersectEntity("Posts", "Users"));
Inflector::$railsStyle = FALSE;
$this->assertSame("MessagesPosts", Inflector::intersectEntity("\Front\Mailer\Message", "\Front\Blog\Post"));
$this->assertSame("MessagesPosts", Inflector::intersectEntity("\Front\Mailer\Messages", "\Front\Blog\Posts"));
$this->assertSame("PostsMessages", Inflector::intersectEntity("\Front\Blog\Post", "\Front\Mailer\Message"));
$this->assertSame("PostsMessages", Inflector::intersectEntity("\Front\Blog\Posts", "\Front\Mailer\Messages"));
$this->assertSame("UsersMessages", Inflector::intersectEntity("\Backend\User", "Front\Mailer\Message"));
$this->assertSame("UsersMessages", Inflector::intersectEntity("\Backend\Users", "Front\Mailer\Messages"));
$this->assertSame("PostsUsers", Inflector::intersectEntity("Front\Blog\Post", "Backend\User"));
$this->assertSame("PostsUsers", Inflector::intersectEntity("Front\Blog\Posts", "Backend\Users"));
$this->assertSame("MessagesPosts", Inflector::intersectEntity("Message", "Post"));
$this->assertSame("MessagesPosts", Inflector::intersectEntity("Messages", "Posts"));
$this->assertSame("UsersMessages", Inflector::intersectEntity("User", "Message"));
$this->assertSame("UsersMessages", Inflector::intersectEntity("Users", "Messages"));
$this->assertSame("PostsUsers", Inflector::intersectEntity("Post", "User"));
$this->assertSame("PostsUsers", Inflector::intersectEntity("Posts", "Users"));
}
public function testCamelize() {
$this->assertSame('ActiveRecord', Inflector::camelize('active_record'));
$this->assertSame('activeRecord', Inflector::camelize('active_record', FALSE));
$this->markTestIncomplete();
$this->assertSame('ActiveRecord\Errors', Inflector::camelize('./ActiveRecord/Errors'));
$this->assertSame('activeRecord\Errors', Inflector::camelize('./ActiveRecord/Errors', FALSE));
$this->assertSame('ActiveRecord\Errors', Inflector::camelize('active_record/errors'));
$this->assertSame('activeRecord\Errors', Inflector::camelize('active_record/errors', FALSE));
}
public function testDasherize() {
$this->assertSame('puni-puni', Inflector::dasherize('puni_puni'));
}
public function testUnderscore() {
$this->assertSame('active_record', Inflector::underscore('ActiveRecord'));
$this->markTestIncomplete();
$this->assertSame('active_record/errors', Inflector::underscore('ActiveRecord::Errors'));
}
public function testTitleize() {
$this->assertSame('Man From The Boondocks', Inflector::titleize('man from the boondocks'));
$this->assertSame('X-Men: The Last Stand', Inflector::titleize('x-men: the last stand'));
}
public function testTableize() {
Inflector::$railsStyle = TRUE;
$this->assertSame('raw_scaled_scorers', Inflector::tableize('RawScaledScorer'));
$this->assertSame('egg_and_hams', Inflector::tableize('egg_and_ham'));
$this->assertSame('fancy_categories', Inflector::tableize('fancyCategory'));
$this->assertSame('users', Inflector::tableize('User'));
$this->assertSame('users', Inflector::tableize('UserModel'));
$this->assertSame('models', Inflector::tableize('Model'));
$this->assertSame('models', Inflector::tableize('ModelModel'));
$this->assertSame('modelations', Inflector::tableize('Modelation'));
$this->assertSame('modelations', Inflector::tableize('ModelationModel'));
Inflector::$railsStyle = FALSE;
$this->assertSame('RawScaledScorers', Inflector::tableize('RawScaledScorer'));
$this->assertSame('EggAndHams', Inflector::tableize('egg_and_ham'));
$this->assertSame('FancyCategories', Inflector::tableize('fancyCategory'));
$this->assertSame('Users', Inflector::tableize('User'));
$this->assertSame('Users', Inflector::tableize('UserModel'));
$this->assertSame('Models', Inflector::tableize('Model'));
$this->assertSame('Models', Inflector::tableize('ModelModel'));
$this->assertSame('Modelations', Inflector::tableize('Modelation'));
$this->assertSame('Modelations', Inflector::tableize('ModelationModel'));
}
public function testClassify() {
$this->assertSame('EggAndHam', Inflector::classify('egg_and_hams'));
$this->assertSame('Post', Inflector::classify('posts'));
$this->assertSame('Post', Inflector::classify('post'));
$this->assertSame('RawScaledScorer', Inflector::classify('raw_scaled_scorers'));
$this->assertSame('FancyCategory', Inflector::classify('fancy_categories'));
$this->assertSame('EggAndHam', Inflector::classify('EggAndHams'));
$this->assertSame('Post', Inflector::classify('Posts'));
$this->assertSame('Post', Inflector::classify('Post'));
$this->assertSame('RawScaledScorer', Inflector::classify('RawScaledScorers'));
$this->assertSame('FancyCategory', Inflector::classify('FancyCategories'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment