How to use __toString method of Type class

Best Mockery code snippet using Type.__toString

FormTest.php

Source:FormTest.php Github

copy

Full Screen

...22 23 public function testFormCanBeRendered()24 {25 $form = new Form([Form::TEXT]);26 $this->assertRegExp('/^<form/', $form->__toString());27 $this->assertRegExp('/<input[\s]+type="text"[\s]+>/', $form->__toString());28 $this->assertRegExp('/<\/form>$/', $form->__toString());29 }30 31 public function testExceptionIsThrownIfNoElementsAreProvided()32 {33 $this->setExpectedException(34 Form\Exception::Class,35 '',36 Form\Exception::NO_ELEMENT_PROVIDED37 );38 $form = new Form([]);39 }40 41 public function testFormMethodDefaultsToPost()42 {43 $form = new Form([Form::TEXT]);44 $this->assertContains('method="post"', $form->__toString());45 }46 47 public function testMethodCanBeSetToGet()48 {49 $form = new Form([Form::TEXT], 'get');50 $this->assertContains('method="get"', $form->__toString());51 }52 53 public function testExceptionIsThrownIfMethodIsNotPostOrGet()54 {55 $this->setExpectedException(56 Form\Exception::Class,57 '',58 Form\Exception::INVALID_METHOD_PROVIDED59 );60 new Form([Form::TEXT], 'invalid');61 }62 63 public function testNoTargetIsSetByDefault()64 {65 $form = new Form([Form::TEXT], 'post');66 $this->assertNotContains('target', $form->__toString());67 }68 69 public function testFormTargetCanBeSet()70 {71 $form = new Form([Form::TEXT], 'post', '/example/path');72 $this->assertContains('target="/example/path"', $form->__toString());73 }74 75 public function testExceptionIsThrownIfProvidedTargetIsNotAString()76 {77 $this->setExpectedException(78 Form\Exception::Class,79 '',80 Form\Exception::NON_STRING_PROVIDED_AS_TARGET81 );82 new Form([Form::TEXT], 'post', true);83 }84 85 public function testMultipleElementsCanBeProvidedAndAreRendered()86 {87 $form = new Form([88 Form::TEXT,89 Form::SUBMIT90 ]);91 $this->assertRegExp(92 '/<input(?:[\s]+[^\s>]*)*?[\s]+type="text"(?:[\s]+[^\s>]*)*?>/',93 $form->__toString()94 );95 $this->assertRegExp(96 '/<input(?:[\s]+[^\s>]*)*?[\s]+type="submit"(?:[\s]+[^\s>]*)*?>/',97 $form->__toString()98 );99 }100 101 public function testElementKeyMustBeEqualToAClassConstant()102 {103 $this->setExpectedException(104 Form\Exception::Class,105 '',106 Form\Exception::INVALID_ELEMENT_KEY_PROVIDED107 );108 new Form([109 Form::TEXT,110 999111 ]);112 }113 114 public function testElementKeyCanBeProvidedInsideArray()115 {116 $form = new Form([117 ['element' => Form::TEXT]118 ]);119 $this->assertRegExp(120 '/<input(?:[\s]+[^\s>]*)*?[\s]+type="text"(?:[\s]+[^\s>]*)*?>/',121 $form->__toString()122 );123 }124 125 public function testArrayElementDefinitionMustIncludeElementKey()126 {127 $this->setExpectedException(128 Form\Exception::Class,129 '',130 Form\Exception::INVALID_ELEMENT_DEFINITION131 );132 new Form([133 ['notElement' => Form::TEXT]134 ]);135 }136 137 public function testExceptionIsThrownIfElementKeyIsNotAnIntegerOrArray()138 {139 $this->setExpectedException(140 Form\Exception::Class,141 '',142 Form\Exception::INVALID_ELEMENT_DEFINITION143 );144 new Form([145 Form::TEXT => true146 ]);147 }148 149 public function testLabelCanBeCreatedForElementAndForAttributeIsSetCorrectly()150 {151 $form = new Form([152 [153 'element' => Form::TEXT,154 'label' => 'My Label',155 'id' => 'my-element'156 ]157 ]);158 $this->assertRegExp(159 '/<input(?:[\s]+[^\s>]*)*?[\s]+(?:type="text"[\s]+id="my-element"|'.160 'id="my-element"[\s]+type="text")(?:[\s]+[^\s>]*)*?>/',161 $form->__toString()162 );163 $this->assertRegExp(164 '/<label(?:[\s]+[^\s>]*)*?[\s]+for="my-element"'.165 '(?:[\s]+[^\s>]*)*?>[\s]*My Label[\s]*<\/label>/',166 $form->__toString()167 );168 }169 170 public function testLabelIsShownDirectlyBeforeRelatedInput()171 {172 $form = new Form([173 [174 'element' => Form::TEXT,175 'label' => 'My Label',176 'id' => 'my-element'177 ]178 ]);179 $this->assertRegExp(180 '/<label[^>]+>[^<]+<\/label>[\s]*<input[^>]+>/',181 $form->__toString()182 );183 }184 185 public function testExceptionIsThrownIfLabelIsDeclaredButNoIDIsDeclared()186 {187 $this->setExpectedException(188 Form\Exception::Class,189 '',190 Form\Exception::MISSING_VALUE_IN_ELEMENT_DECLARATION191 );192 $form = new Form([193 [194 'element' => Form::TEXT,195 'label' => 'My Label'196 ]197 ]);198 }199 200 public function testExceptionIsThrownIfLabelIsNotAString()201 {202 $this->setExpectedException(203 Form\Exception::Class,204 '',205 Form\Exception::INVALID_VALUE_IN_ELEMENT_DECLARATION206 );207 $form = new Form([208 [209 'element' => Form::TEXT,210 'label' => ['My Label'],211 'id' => 'my-element'212 ]213 ]);214 }215 216 public function testExceptionIsThrownIfContentIsProvidedForASelfClosingElementType()217 {218 $this->setExpectedException(219 Form\Exception::Class,220 '',221 Form\Exception::CONTENT_PROVIDED_FOR_SELF_CLOSING_TAG222 );223 new Form([224 [225 'element' => Form::TEXT,226 'content' => 'I\'m the content'227 ]228 ]);229 }230 231 public function testElementCanBeURL()232 {233 $form = new Form([Form::URL]);234 $this->assertRegExp('/<input[\s]+type="url"[\s]+>/', $form->__toString());235 }236 237 public function testElementCanBeTelephoneNumber()238 {239 $form = new Form([Form::TEL]);240 $this->assertRegExp('/<input[\s]+type="tel"[\s]+>/', $form->__toString());241 }242 243 public function testElementCanBeEmailAddress()244 {245 $form = new Form([Form::EMAIL]);246 $this->assertRegExp('/<input[\s]+type="email"[\s]+>/', $form->__toString());247 }248 249 public function testElementCanBeSearchField()250 {251 $form = new Form([Form::SEARCH]);252 $this->assertRegExp('/<input[\s]+type="search"[\s]+>/', $form->__toString());253 }254 255 public function testElementCanBeNumber()256 {257 $form = new Form([Form::NUMBER]);258 $this->assertRegExp('/<input[\s]+type="number"[\s]+>/', $form->__toString());259 }260 261 public function testElementCanBeRange()262 {263 $form = new Form([Form::RANGE]);264 $this->assertRegExp('/<input[\s]+type="range"[\s]+>/', $form->__toString());265 }266 267 public function testElementCanBeDateTimeLocal()268 {269 $form = new Form([Form::DATE_TIME_LOCAL]);270 $this->assertRegExp('/<input[\s]+type="datetime-local"[\s]+>/', $form->__toString());271 }272 273 public function testElementCanBeDate()274 {275 $form = new Form([Form::DATE]);276 $this->assertRegExp('/<input[\s]+type="date"[\s]+>/', $form->__toString());277 }278 279 public function testElementCanBeTime()280 {281 $form = new Form([Form::TIME]);282 $this->assertRegExp('/<input[\s]+type="time"[\s]+>/', $form->__toString());283 }284 285 public function testElementCanBeWeek()286 {287 $form = new Form([Form::WEEK]);288 $this->assertRegExp('/<input[\s]+type="week"[\s]+>/', $form->__toString());289 }290 291 public function testElementCanBeMonth()292 {293 $form = new Form([Form::MONTH]);294 $this->assertRegExp('/<input[\s]+type="month"[\s]+>/', $form->__toString());295 }296 297 public function testElementCanBeColor()298 {299 $form = new Form([Form::COLOR]);300 $this->assertRegExp('/<input[\s]+type="color"[\s]+>/', $form->__toString());301 }302 303 public function testElementCanBeTextArea()304 {305 $form = new Form([Form::TEXTAREA]);306 $this->assertRegExp('/<textarea[\s]*>[\s]*<\/textarea>/', $form->__toString());307 }308 309 public function testTextAreaElementCanContainContent()310 {311 $form = new Form([312 [313 'element' => Form::TEXTAREA,314 'content' => 'I\'m the content'315 ]316 ]);317 $this->assertRegExp('/<textarea[\s]*>[\s]*I\'m the content[\s]*<\/textarea>/', $form->__toString());318 }319 320 public function testElementCanBeSelectAndOptionsAreRendered()321 {322 $form = new Form([323 [324 'element' => Form::SELECT,325 'options' => ['One', 'Two']326 ]327 ]);328 $this->assertRegExp(329 '/<select[\s]*>[\s]*<option[\s]*>[\s]*One[\s]*<\/option>[\s]*'.330 '<option[\s]*>[\s]*Two[\s]*<\/option>[\s]*<\/select>/',331 $form->__toString()332 );333 }334 335 public function testSelectElementCanRenderOptionsWithProvidedValues()336 {337 $form = new Form([338 [339 'element' => Form::SELECT,340 'options' => [341 'one' => 'Uno',342 'two' => 'Dos'343 ]344 ]345 ]);346 $this->assertRegExp(347 '/<select[\s]*>[\s]*<option[\s]*value="one"[\s]*>[\s]*Uno[\s]*<\/option>[\s]*'.348 '<option[\s]*value="two"[\s]*>[\s]*Dos[\s]*<\/option>[\s]*<\/select>/',349 $form->__toString()350 );351 }352 353 public function testDataListCanBeRenderedForInputElementAndIdAndListAttributesAreIncluded()354 {355 $form = new Form([356 [357 'element' => Form::TEXT,358 'datalist' => [359 'id' => 'my-list',360 'options' => ['One', 'Two']361 ]362 ]363 ]);364 $this->assertRegExp(365 '/<input[\s]+(?:list="my-list"[\s]+type="text"|type="text"[\s]+list="my-list")[\s]*>/',366 $form->__toString()367 );368 $this->assertRegExp(369 '/<datalist[\s]+id="my-list"[\s]*>[\s]*<option[\s]+value="One"[\s]*>[\s]*'.370 '<option[\s]+value="Two"[\s]*>[\s]*<\/datalist>/',371 $form->__toString()372 );373 }374 375 public function testDataListCanBeProvidedWithNoIdAndARandomOneIsGenerated()376 {377 $form = new Form([378 [379 'element' => Form::TEXT,380 'datalist' => ['One', 'Two']381 ]382 ]);383 $this->assertRegExp(384 '/<input[\s]+(?:list="list-[a-z]{6}"[\s]+type="text"|type="text"[\s]+' .385 'list="list-[a-z]{6}")[\s]*>/',386 $form->__toString()387 );388 $this->assertRegExp(389 '/<datalist[\s]+id="list-[a-z]{6}"[\s]*>[\s]*<option[\s]+value="One"[\s]*>[\s]*' .390 '<option[\s]+value="Two"[\s]*>[\s]*<\/datalist>/',391 $form->__toString()392 );393 preg_match(394 '/<input[\s]+(?:list="(list-[a-z]{6})"[\s]+type="text"|type="text"[\s]+' .395 'list="(list-[a-z]{6})")[\s]*>/',396 $form,397 $inputMatch398 );399 preg_match(400 '/<datalist[\s]+id="(list-[a-z]{6})"[\s]*>[\s]*<option[\s]+value="One"[\s]*>[\s]*' .401 '<option[\s]+value="Two"[\s]*>[\s]*<\/datalist>/',402 $form,403 $dataListMatch404 );405 $this->assertTrue(406 $dataListMatch[1] == $inputMatch[1] ||407 $dataListMatch[1] == $inputMatch[2]408 );409 }410 411 public function testElementCanBeDeclaredWithAutoFocus()412 {413 $form = new Form([414 [415 'element' => Form::TEXT,416 'autofocus' => true417 ]418 ]);419 $this->assertRegExp(420 '/<input[\s]+(?:type="text"[\s]+autofocus|autofocus[\s]*type="text")[\s]*>/',421 $form->__toString()422 );423 }424 425 public function testOnlyOneElementCanBeDeclaredAutoFocus()426 {427 $this->setExpectedException(428 Form\Exception::Class,429 '',430 Form\Exception::DUPLICATE_AUTOFOCUS431 );432 new Form([433 Form::TEXT,434 [435 'element' => Form::TEXT,436 'autofocus' => true437 ],438 [439 'element' => Form::TEXT,440 'autofocus' => true441 ]442 ]);443 }444 445 public function testUnrecognisedDefinitionKeyIsUsedAsAttribute()446 {447 $form = new Form([448 [449 'element' => Form::TEXT,450 'required' => true,451 'anything' => true452 ]453 ]);454 $this->assertRegExp(455 '/<input[\s]+[\sa-z="-]*required(?:[\s]+[\sa-z="-]*)?>/',456 $form->__toString()457 );458 $this->assertRegExp(459 '/<input[\s]+[\sa-z="-]*anything(?:[\s]+[\sa-z="-]*)?>/',460 $form->__toString()461 );462 }463 464 public function testUnrecognisedAttributeCanContainSingleValue()465 {466 $form = new Form([467 [468 'element' => Form::TEXT,469 'class' => 'some-class'470 ]471 ]);472 $this->assertRegExp(473 '/<input[\s]+[\sa-z="-]*class="some-class"(?:[\s]+[\sa-z="-]*)?>/',474 $form->__toString()475 );476 }477 478 public function testUnrecognisedAttributeCanContainMultipleValues()479 {480 $form = new Form([481 [482 'element' => Form::TEXT,483 'class' => ['class-one', 'class-two']484 ]485 ]);486 $this->assertRegExp(487 '/<input[\s]+[\sa-z="-]*class="(?:class-one class-two|class-two class-one)' .488 '"(?:[\s]+[\sa-z="-]*)?>/',489 $form->__toString()490 );491 }492 493 // @todo button - http://reference.sitepoint.com/html/button494 // @todo enctype - http://reference.sitepoint.com/html/form495 496}...

Full Screen

Full Screen

ReservationEvents.php

Source:ReservationEvents.php Github

copy

Full Screen

...59 $this->priority = $priority;60 $this->series = $series;61 $this->id = $this->series->SeriesId();62 }63 public function __toString()64 {65 return sprintf("%s-%s", get_class($this), $this->id);66 }67 public static function Compare(SeriesEvent $event1, SeriesEvent $event2)68 {69 if ($event1->GetPriority() == $event2->GetPriority())70 {71 return 0;72 }73 // higher priority should be at the top74 return ($event1->GetPriority() > $event2->GetPriority()) ? -1 : 1;75 }76}77class InstanceAddedEvent extends SeriesEvent78{79 /**80 * @var Reservation81 */82 private $instance;83 /**84 * @return Reservation85 */86 public function Instance()87 {88 return $this->instance;89 }90 public function __construct(Reservation $reservationInstance, ExistingReservationSeries $series)91 {92 $this->instance = $reservationInstance;93 parent::__construct($series, SeriesEventPriority::Lowest);94 }95 public function __toString()96 {97 return sprintf("%s%s", get_class($this), $this->instance->ReferenceNumber());98 }99}100class InstanceRemovedEvent extends SeriesEvent101{102 /**103 * @var Reservation104 */105 private $instance;106 /**107 * @return Reservation108 */109 public function Instance()110 {111 return $this->instance;112 }113 public function __construct(Reservation $reservationInstance, ExistingReservationSeries $series)114 {115 $this->instance = $reservationInstance;116 parent::__construct($series, SeriesEventPriority::Highest);117 }118 public function __toString()119 {120 return sprintf("%s%s", get_class($this), $this->instance->ReferenceNumber());121 }122}123class InstanceUpdatedEvent extends SeriesEvent124{125 /**126 * @var Reservation127 */128 private $instance;129 /**130 * @return Reservation131 */132 public function Instance()133 {134 return $this->instance;135 }136 public function __construct(Reservation $reservationInstance, ExistingReservationSeries $series)137 {138 $this->instance = $reservationInstance;139 parent::__construct($series, SeriesEventPriority::Low);140 }141 public function __toString()142 {143 return sprintf("%s%s", get_class($this), $this->instance->ReferenceNumber());144 }145}146class SeriesBranchedEvent extends SeriesEvent147{148 public function __construct(ReservationSeries $series)149 {150 parent::__construct($series);151 }152 public function __toString()153 {154 return sprintf("%s%s", get_class($this), $this->series->SeriesId());155 }156}157class SeriesDeletedEvent extends SeriesEvent158{159 public function __construct(ExistingReservationSeries $series)160 {161 parent::__construct($series, SeriesEventPriority::Highest);162 }163 /**164 * @return ExistingReservationSeries165 */166 public function Series()167 {168 return $this->series;169 }170 public function __toString()171 {172 return sprintf("%s%s", get_class($this), $this->series->SeriesId());173 }174}175class ResourceRemovedEvent extends SeriesEvent176{177 /**178 * @var BookableResource179 */180 private $resource;181 public function __construct(BookableResource $resource, ExistingReservationSeries $series)182 {183 $this->resource = $resource;184 parent::__construct($series, SeriesEventPriority::Highest);185 }186 /**187 * @return BookableResource188 */189 public function Resource()190 {191 return $this->resource;192 }193 /**194 * @return int195 */196 public function ResourceId()197 {198 return $this->resource->GetResourceId();199 }200 /**201 * @return ExistingReservationSeries202 */203 public function Series()204 {205 return $this->series;206 }207 public function __toString()208 {209 return sprintf("%s%s%s", get_class($this), $this->ResourceId(), $this->series->SeriesId());210 }211}212class ResourceAddedEvent extends SeriesEvent213{214 /**215 * @var BookableResource216 */217 private $resource;218 /**219 * @var int|ResourceLevel220 */221 private $resourceLevel;222 /**223 * @param BookableResource $resource224 * @param int|ResourceLevel $resourceLevel225 * @param ExistingReservationSeries $series226 */227 public function __construct(BookableResource $resource, $resourceLevel, ExistingReservationSeries $series)228 {229 $this->resource = $resource;230 $this->resourceLevel = $resourceLevel;231 parent::__construct($series, SeriesEventPriority::Low);232 }233 /**234 * @return BookableResource235 */236 public function Resource()237 {238 return $this->resource;239 }240 public function ResourceId()241 {242 return $this->resource->GetResourceId();243 }244 /**245 * @return ExistingReservationSeries246 */247 public function Series()248 {249 return $this->series;250 }251 public function __toString()252 {253 return sprintf("%s%s%s", get_class($this), $this->ResourceId(), $this->series->SeriesId());254 }255 public function ResourceLevel()256 {257 return $this->resourceLevel;258 }259}260class SeriesApprovedEvent extends SeriesEvent261{262 public function __construct(ExistingReservationSeries $series)263 {264 parent::__construct($series);265 }266 public function __toString()267 {268 return sprintf("%s%s", get_class($this), $this->series->SeriesId());269 }270}271class AccessoryAddedEvent extends SeriesEvent272{273 /**274 * @return int275 */276 public function AccessoryId()277 {278 return $this->accessory->AccessoryId;279 }280 /**281 * @return int282 */283 public function Quantity()284 {285 return $this->accessory->QuantityReserved;286 }287 /**288 * @var \ReservationAccessory289 */290 private $accessory;291 public function __construct(ReservationAccessory $accessory, ExistingReservationSeries $series)292 {293 $this->accessory = $accessory;294 parent::__construct($series, SeriesEventPriority::Low);295 }296 public function __toString()297 {298 return sprintf("%s%s", get_class($this), $this->accessory->__toString());299 }300}301class AccessoryRemovedEvent extends SeriesEvent302{303 /**304 * @return int305 */306 public function AccessoryId()307 {308 return $this->accessory->AccessoryId;309 }310 /**311 * @var \ReservationAccessory312 */313 private $accessory;314 public function __construct(ReservationAccessory $accessory, ExistingReservationSeries $series)315 {316 $this->accessory = $accessory;317 parent::__construct($series, SeriesEventPriority::Highest);318 }319 public function __toString()320 {321 return sprintf("%s%s", get_class($this), $this->accessory->__toString());322 }323}324class AttributeAddedEvent extends SeriesEvent325{326 /**327 * @return int328 */329 public function AttributeId()330 {331 return $this->attribute->AttributeId;332 }333 /**334 * @return mixed335 */336 public function Value()337 {338 return $this->attribute->Value;339 }340 /**341 * @var \AttributeValue342 */343 private $attribute;344 public function __construct(AttributeValue $attribute, ExistingReservationSeries $series)345 {346 $this->attribute = $attribute;347 parent::__construct($series, SeriesEventPriority::Low);348 }349 public function __toString()350 {351 return sprintf("%s%s", get_class($this), $this->attribute->__toString());352 }353}354class AttributeRemovedEvent extends SeriesEvent355{356 /**357 * @return int358 */359 public function AttributeId()360 {361 return $this->attribute->AttributeId;362 }363 /**364 * @var \AttributeValue365 */366 private $attribute;367 public function __construct(AttributeValue $attribute, ExistingReservationSeries $series)368 {369 $this->attribute = $attribute;370 parent::__construct($series, SeriesEventPriority::Highest);371 }372 public function __toString()373 {374 return sprintf("%s%s", get_class($this), $this->attribute->__toString());375 }376}377class OwnerChangedEvent extends SeriesEvent378{379 /**380 * @var int381 */382 private $oldOwnerId;383 /**384 * @var int385 */386 private $newOwnerId;387 /**388 * @param ExistingReservationSeries $series389 * @param int $oldOwnerId390 * @param int $newOwnerId391 */392 public function __construct(ExistingReservationSeries $series, $oldOwnerId, $newOwnerId)393 {394 $this->series = $series;395 $this->oldOwnerId = $oldOwnerId;396 $this->newOwnerId = $newOwnerId;397 }398 /**399 * @return ExistingReservationSeries400 */401 public function Series()402 {403 return $this->series;404 }405 /**406 * @return int407 */408 public function OldOwnerId()409 {410 return $this->oldOwnerId;411 }412 /**413 * @return int414 */415 public function NewOwnerId()416 {417 return $this->newOwnerId;418 }419 public function __toString()420 {421 return sprintf("%s%s%s%s", get_class($this), $this->OldOwnerId(), $this->NewOwnerId(),422 $this->series->SeriesId());423 }424}425class AttachmentRemovedEvent extends SeriesEvent426{427 /**428 * @var int429 */430 private $fileId;431 /**432 * @var string433 */434 private $extension;435 /**436 * @param ExistingReservationSeries $series437 * @param int $fileId438 * @param string $extension439 */440 public function __construct(ExistingReservationSeries $series, $fileId, $extension)441 {442 parent::__construct($series, SeriesEventPriority::Lowest);443 $this->fileId = $fileId;444 $this->extension = $extension;445 }446 /**447 * @return int448 */449 public function FileId()450 {451 return $this->fileId;452 }453 /**454 * return string455 */456 public function FileName()457 {458 return $this->fileId . '.' . $this->extension;459 }460 public function __toString()461 {462 return sprintf("%s%s%s", get_class($this), $this->FileId(), $this->series->SeriesId());463 }464}465class ReminderAddedEvent extends SeriesEvent466{467 private $minutesPrior;468 private $reminderType;469 /**470 * @param ExistingReservationSeries $series471 * @param int $minutesPrior472 * @param ReservationReminderType $reminderType473 */474 public function __construct(ExistingReservationSeries $series, $minutesPrior, $reminderType)475 {476 $this->series = $series;477 $this->minutesPrior = $minutesPrior;478 $this->reminderType = $reminderType;479 }480 public function __toString()481 {482 return sprintf("%s%s%s%s", get_class($this), $this->MinutesPrior(), $this->ReminderType(),483 $this->series->SeriesId());484 }485 /**486 * @return int487 */488 public function MinutesPrior()489 {490 return $this->minutesPrior;491 }492 /**493 * @return ReservationReminderType494 */495 public function ReminderType()496 {497 return $this->reminderType;498 }499}500class ReminderRemovedEvent extends SeriesEvent501{502 /**503 * @var int|ReservationReminderType504 */505 private $reminderType;506 /**507 * @return ReservationReminderType508 */509 public function ReminderType()510 {511 return $this->reminderType;512 }513 /**514 * @param ExistingReservationSeries $series515 * @param int|ReservationReminderType $reminderType516 */517 public function __construct(ExistingReservationSeries $series, $reminderType)518 {519 $this->series = $series;520 $this->reminderType = $reminderType;521 }522 public function __toString()523 {524 return sprintf("%s%s%s", get_class($this), $this->ReminderType(),525 $this->series->SeriesId());526 }527}528?>...

Full Screen

Full Screen

SplString.php

Source:SplString.php Github

copy

Full Screen

...20 return $this;21 }22 function split( int $length = 1 ) : SplArray23 {24 return new SplArray( str_split( $this->__toString(), $length ) );25 }26 function explode( string $delimiter ) : SplArray27 {28 return new SplArray( explode( $delimiter, $this->__toString() ) );29 }30 function subString( int $start, int $length ) : SplString31 {32 return $this->setString( substr( $this->__toString(), $start, $length ) );33 }34 function encodingConvert( string $desEncoding, $detectList35 = [36 'UTF-8',37 'ASCII',38 'GBK',39 'GB2312',40 'LATIN1',41 'BIG5',42 "UCS-2",43 ] ) : SplString44 {45 $fileType = mb_detect_encoding( $this->__toString(), $detectList );46 if( $fileType != $desEncoding ){47 $this->setString( mb_convert_encoding( $this->__toString(), $desEncoding, $fileType ) );48 }49 return $this;50 }51 function utf8() : SplString52 {53 return $this->encodingConvert( "UTF-8" );54 }55 /*56 * special function for unicode57 */58 function unicodeToUtf8() : SplString59 {60 $string = preg_replace_callback( '/\\\\u([0-9a-f]{4})/i', function( $matches ){61 return mb_convert_encoding( pack( "H*", $matches[1] ), "UTF-8", "UCS-2BE" );62 }, $this->__toString() );63 return $this->setString( $string );64 }65 function toUnicode() : SplString66 {67 $raw = (string)$this->encodingConvert( "UCS-2" );68 $len = strlen( $raw );69 $str = '';70 for( $i = 0 ; $i < $len - 1 ; $i = $i + 2 ){71 $c = $raw[$i];72 $c2 = $raw[$i + 1];73 if( ord( $c ) > 0 ){ //两个字节的文字74 $str .= '\u'.base_convert( ord( $c ), 10, 16 ).str_pad( base_convert( ord( $c2 ), 10, 16 ), 2, 0, STR_PAD_LEFT );75 } else{76 $str .= '\u'.str_pad( base_convert( ord( $c2 ), 10, 16 ), 4, 0, STR_PAD_LEFT );77 }78 }79 $string = strtoupper( $str );//转换为大写80 return $this->setString( $string );81 }82 function compare( string $str, int $ignoreCase = 0 ) : int83 {84 if( $ignoreCase ){85 return strcasecmp( $this->__toString(), $str );86 } else{87 return strcmp( $this->__toString(), $str );88 }89 }90 function lTrim( string $charList = " \t\n\r\0\x0B" ) : SplString91 {92 return $this->setString( ltrim( $this->__toString(), $charList ) );93 }94 function rTrim( string $charList = " \t\n\r\0\x0B" ) : SplString95 {96 return $this->setString( rtrim( $this->__toString(), $charList ) );97 }98 function trim( string $charList = " \t\n\r\0\x0B" ) : SplString99 {100 return $this->setString( trim( $this->__toString(), $charList ) );101 }102 function pad( int $length, string $padString = null, int $pad_type = STR_PAD_RIGHT ) : SplString103 {104 return $this->setString( str_pad( $this->__toString(), $length, $padString, $pad_type ) );105 }106 function repeat( int $times ) : SplString107 {108 return $this->setString( str_repeat( $this->__toString(), $times ) );109 }110 function length() : int111 {112 return strlen( $this->__toString() );113 }114 function upper() : SplString115 {116 return $this->setString( strtoupper( $this->__toString() ) );117 }118 function lower() : SplString119 {120 return $this->setString( strtolower( $this->__toString() ) );121 }122 function stripTags( string $allowable_tags = null ) : SplString123 {124 return $this->setString( strip_tags( $this->__toString(), $allowable_tags ) );125 }126 function replace( string $find, string $replaceTo ) : SplString127 {128 return $this->setString( str_replace( $find, $replaceTo, $this->__toString() ) );129 }130 function between( string $startStr, string $endStr ) : SplString131 {132 $explode_arr = explode( $startStr, $this->__toString() );133 if( isset( $explode_arr[1] ) ){134 $explode_arr = explode( $endStr, $explode_arr[1] );135 return $this->setString( $explode_arr[0] );136 } else{137 return $this->setString( '' );138 }139 }140 public function regex( $regex, bool $rawReturn = false )141 {142 preg_match( $regex, $this->__toString(), $result );143 if( !empty( $result ) ){144 if( $rawReturn ){145 return $result;146 } else{147 return $result[0];148 }149 } else{150 return null;151 }152 }153 public function exist( string $find, bool $ignoreCase = true ) : bool154 {155 if( $ignoreCase ){156 $label = stripos( $this->__toString(), $find );157 } else{158 $label = strpos( $this->__toString(), $find );159 }160 return $label === false ? false : true;161 }162 /**163 * 转换为烤串164 */165 function kebab() : SplString166 {167 return $this->snake( '-' );168 }169 /**170 * 转为蛇的样子171 * @param string $delimiter172 */173 function snake( string $delimiter = '_' ) : SplString174 {175 $string = $this->__toString();176 if( !ctype_lower( $string ) ){177 $string = preg_replace( '/\s+/u', '', ucwords( $this->__toString() ) );178 $string = $this->setString( preg_replace( '/(.)(?=[A-Z])/u', '$1'.$delimiter, $string ) );179 $this->setString( $string );180 $this->lower();181 }182 return $this;183 }184 /**185 * 转为大写的大写186 */187 function studly() : SplString188 {189 $value = ucwords( str_replace( ['-', '_'], ' ', $this->__toString() ) );190 return $this->setString( str_replace( ' ', '', $value ) );191 }192 /**193 * 驼峰194 *195 */196 function camel() : SplString197 {198 $this->studly();199 return $this->setString( lcfirst( $this->__toString() ) );200 }201 /**202 * 用数组逐个字符203 * @param string $search204 * @param array $replace205 */206 public function replaceArray( string $search, array $replace ) : SplString207 {208 foreach( $replace as $value ){209 $this->setString( $this->replaceFirst( $search, $value ) );210 }211 return $this;212 }213 /**214 * 替换字符串中给定值的第一次出现。215 * @param string $search216 * @param string $replace217 */218 public function replaceFirst( string $search, string $replace ) : SplString219 {220 if( $search == '' ){221 return $this;222 }223 $position = strpos( $this->__toString(), $search );224 if( $position !== false ){225 return $this->setString( substr_replace( $this->__toString(), $replace, $position, strlen( $search ) ) );226 }227 return $this;228 }229 /**230 * 替换字符串中给定值的最后一次出现。231 * @param string $search232 * @param string $replace233 */234 public function replaceLast( string $search, string $replace ) : SplString235 {236 $position = strrpos( $this->__toString(), $search );237 if( $position !== false ){238 return $this->setString( substr_replace( $this->__toString(), $replace, $position, strlen( $search ) ) );239 }240 return $this;241 }242 /**243 * 以一个给定值的单一实例开始一个字符串244 *245 * @param string $prefix246 */247 public function start( string $prefix ) : SplString248 {249 $quoted = preg_quote( $prefix, '/' );250 return $this->setString( $prefix.preg_replace( '/^(?:'.$quoted.')+/u', '', $this->__toString() ) );251 }252 /**253 * 在给定的值之后返回字符串的其余部分。254 *255 * @param string $search256 */257 function after( string $search ) : SplString258 {259 if( $search === '' ){260 return $this;261 } else{262 return $this->setString( array_reverse( explode( $search, $this->__toString(), 2 ) )[0] );263 }264 }265 /**266 * 在给定的值之前获取字符串的一部分267 *268 * @param string $search269 */270 function before( string $search ) : SplString271 {272 if( $search === '' ){273 return $this;274 } else{275 return $this->setString( explode( $search, $this->__toString() )[0] );276 }277 }278 /**279 * 确定给定的字符串是否以给定的子字符串结束280 *281 * @param string $haystack282 * @param string|array $needles283 * @return bool284 */285 public function endsWith( $needles ) : bool286 {287 foreach( (array)$needles as $needle ){288 if( substr( $this->__toString(), - strlen( $needle ) ) === (string)$needle ){289 return true;290 }291 }292 return false;293 }294 /**295 * 确定给定的字符串是否从给定的子字符串开始296 *297 * @param string $haystack298 * @param string|array $needles299 * @return bool300 */301 public function startsWith( $needles ) : bool302 {303 foreach( (array)$needles as $needle ){304 if( $needle !== '' && substr( $this->__toString(), 0, strlen( $needle ) ) === (string)$needle ){305 return true;306 }307 }308 return false;309 }310}...

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$obj = new Type();2echo $obj;3$obj = new Type();4echo $obj;5$obj = new Type();6echo $obj;7$obj = new Type();8echo $obj;9$obj = new Type();10echo $obj;11$obj = new Type();12echo $obj;13$obj = new Type();14echo $obj;15$obj = new Type();16echo $obj;17$obj = new Type();18echo $obj;19$obj = new Type();20echo $obj;21$obj = new Type();22echo $obj;23$obj = new Type();24echo $obj;25$obj = new Type();26echo $obj;27$obj = new Type();28echo $obj;29$obj = new Type();30echo $obj;31$obj = new Type();32echo $obj;33$obj = new Type();34echo $obj;35$obj = new Type();36echo $obj;37$obj = new Type();38echo $obj;

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$var = new Type();2echo $var;3$var = new Type();4echo $var;5$var = new Type();6echo $var;7$var = new Type();8echo $var;9$var = new Type();10echo $var;11$var = new Type();12echo $var;13$var = new Type();14echo $var;15$var = new Type();16echo $var;17$var = new Type();18echo $var;19$var = new Type();20echo $var;21$var = new Type();22echo $var;23$var = new Type();24echo $var;25$var = new Type();26echo $var;27$var = new Type();28echo $var;29$var = new Type();30echo $var;31$var = new Type();32echo $var;33$var = new Type();34echo $var;35$var = new Type();36echo $var;

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$myType = new Type();2$myType->setMyVar('value');3echo $myType;4$myType = new Type();5$myType->setMyVar('value');6echo $myType;7$myType = new Type();8$myType->setMyVar('value');9echo $myType;10$myType = new Type();11$myType->setMyVar('value');12echo $myType;13$myType = new Type();14$myType->setMyVar('value');15echo $myType;16$myType = new Type();17$myType->setMyVar('value');18echo $myType;19$myType = new Type();20$myType->setMyVar('value');21echo $myType;22$myType = new Type();23$myType->setMyVar('value');24echo $myType;25$myType = new Type();26$myType->setMyVar('value');27echo $myType;28$myType = new Type();29$myType->setMyVar('value');30echo $myType;31$myType = new Type();32$myType->setMyVar('value');33echo $myType;34$myType = new Type();35$myType->setMyVar('value');36echo $myType;37$myType = new Type();38$myType->setMyVar('value');

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$myType = new Type();2$myType->name = 'My Name';3echo $myType;4require_once('1.php');5$myType = new Type();6$myType->name = 'My Name';7echo $myType;8The __toString() method is called when an object is used in a string context. The __toString() method is called when an object is used in a string context

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1$a = new Type('a');2$a->set('b');3echo $a;4$a = new Type('a');5$a->set('b');6echo $a;7$a = new Type('a');8$a->set('b');9echo $a;10$a = new Type('a');11$a->set('b');12echo $a;13$a = new Type('a');14$a->set('b');15echo $a;16$a = new Type('a');17$a->set('b');18echo $a;19$a = new Type('a');20$a->set('b');21echo $a;22$a = new Type('a');23$a->set('b');24echo $a;25$a = new Type('a');26$a->set('b');27echo $a;28$a = new Type('a');29$a->set('b');30echo $a;31$a = new Type('a');32$a->set('b');33echo $a;34$a = new Type('a');35$a->set('b');36echo $a;37$a = new Type('a');38$a->set('b');39echo $a;

Full Screen

Full Screen

__toString

Using AI Code Generation

copy

Full Screen

1include 'Type.php';2$obj = new Type();3echo $obj;4include 'Type.php';5$obj = new Type();6echo $obj;7class Type {8 public function __toString() {9 return "String value";10 }11}12This has been a guide to the __toString() method in PHP. Here we discuss how to use the __toString() method in PHP along with practical examples and downloadable code. You may also look at the following articles to learn more –13PHP __call() Method14PHP __callStatic() Method15PHP __get() Method16PHP __set() Method17PHP __isset() Method18PHP __unset() Method19PHP __sleep() Method20PHP __wakeup() Method21PHP __clone() Method22PHP __invoke() Method23PHP __set_state() Method24PHP __debugInfo() Method25PHP __autoload() Method26PHP __destruct() Method27PHP __construct() Method28PHP __call() Method29PHP __callStatic() Method30PHP __get() Method31PHP __set() Method32PHP __isset() Method33PHP __unset() Method34PHP __sleep() Method35PHP __wakeup() Method36PHP __clone() Method37PHP __invoke() Method38PHP __set_state() Method39PHP __debugInfo() Method40PHP __autoload() Method41PHP __destruct() Method42PHP __construct() Method43PHP __call() Method44PHP __callStatic() Method45PHP __get() Method46PHP __set() Method47PHP __isset() Method48PHP __unset() Method

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mockery automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Type

Trigger __toString code on LambdaTest Cloud Grid

Execute automation tests with __toString on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful